title: java - Recursive maze solver not working
body: <p><strong>I have looked at every post with this problem, every guide, every algorithm, and I still cannot find an answer for my problem.</strong> The weird thing is that it doesn't cause any errors, but for every maze it says that it's unsolvable and marks the beginning as a dead end.</p>
  
  <p>I am staring at my code for hours and I cannot figure out what I did wrong!
  My code:</p>
  
  <p>(Other non-important classes - MazeSymbol = enum with symbol names and their string, Position = a row/column class, Coordinate = class that contains a MazeSymbol and a Position))</p>
  
  <p>Maze.java:</p>
  
  <pre><code>private Coordinate[][] map;
  private Position start;
  private Position goal;
  private ArrayList&lt;Coordinate&gt; solutionPath;
  boolean solveable;
  
  public Maze(Coordinate[][] map, Position start, Position goal){
      this.start=start;
      this.map=map;
      this.goal=goal;
      this.solutionPath=new ArrayList&lt;&gt;();
      this.solveable = solveMaze(Coordinate.fromMaze(start, this)); //fromMaze takes a position and finds it's symbol.
  }
  public boolean isSolveable(){
      return solveable;
  }
  private boolean solveMaze(Coordinate c){
      System.out.println("Solving - "+c.getPosition().row+","+c.getPosition().column);
       if(!c.getPosition().isOnMaze(this)){//Checks if it is between the bounds of the maze (larger than 0 and smaller than length both for X and Y)
           System.out.println(c.getPosition().row+","+c.getPosition().column+"Isnt on maze! ");
           return false;
       }
       if(c.getPosition().equals(goal)){
           System.out.println(c.getPosition().row+","+c.getPosition().column+"Is goal!");
           return true;
       }
       if(!c.getSymbol().equals(MazeSymbol.OPEN)){//If it isnt an open path - walked/dead end/wall
           System.out.println(+c.getPosition().row+","+c.getPosition().column+" isn't open!(it's "+c.getSymbol()+")");
           return false;
       }
       map[c.getPosition().getRow()][c.getPosition().getColumn()] = new Coordinate(c.getPosition(), MazeSymbol.PATH);//Replace the open path sign with a walked path sign
       solutionPath.add(c);//Add the coordinate to the solution path
       if(solveMaze(c.setPosition(c.getPosition().positionAbove())))return true;//row-1                  
       if(solveMaze(c.setPosition(c.getPosition().positionLeft())))return true;//column+1
       if(solveMaze(c.setPosition(c.getPosition().positionBelow())))return true;//row+1
       if(solveMaze(c.setPosition(c.getPosition().positionRight())))return true;//column-1
       map[c.getPosition().getRow()][c.getPosition().getColumn()] = c.setSymbol(MazeSymbol.DEAD_END);//If none was the path, mark it as a dead end
       return false;
      }
  </code></pre>
  
  <p>Please help! When I insert this extremely simple maze:</p>
  
  <p>{"O","W","W"},</p>
  
  <p>{"O","O","W"},</p>
  
  <p>{"W","O","O"}</p>
  
  <p>It says it is not solveable, and the <strong>output</strong>:</p>
  
  <p>XWW</p>
  
  <p>OOW</p>
  
  <p>WOO</p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>EDIT:</strong> Changed this line</p>
  
  <pre><code>map[c.getPosition().getRow()][c.getPosition().getColumn()] = new Coordinate(c.getPosition(), MazeSymbol.PATH);
  </code></pre>
  
  <p>and now it isnt working at all, it just gives a StackOverflowError in 2 lines then in the 3rd one over and over again:</p>
  
  <ol>
  <li><code>System.out.println("Solving - "+c.getPosition().row+","+c.getPosition().column);</code></li>
  <li><code>if(solveMaze(c.setPosition(c.getPosition().positionAbove())))return true;</code></li>
  <li><code>if(solveMaze(c.setPosition(c.getPosition().positionRight())))return true;</code></li>
  </ol>