title: Backtracking maze
body: <p>I'm trying to write a maze solver using backtracking. It should see whether it's possible to solve a given puzzle from the starting point S to the end point E. The pseudo code can be seen in this <a href="https://www.topcoder.com/community/data-science/data-science-tutorials/an-introduction-to-recursion-part-2/" rel="nofollow">link</a> here. My implementation looks like this:</p>
  
  <pre><code>const int N = 8; // global var
  
  bool exploreMaze(char maze[][N], int x, int y)
  {
      if(y &gt;= 8 || y &lt; 0 || x &gt;= 7 || x &lt; 0) // null char at end of each 1d array 
          return false;
      if(maze[x][y] == '*')
          return false;
      if(maze[x][y] == 'E')
          return true;
      maze[x][y] = '*'; // set grid to '*' as to not loop infinitely
      if(exploreMaze(maze,  x + 1, y))
      {
          cout &lt;&lt; "up" &lt;&lt; ", ";
          return true;
      }
      if(exploreMaze(maze,  x - 1, y))
      {
          cout &lt;&lt; "down" &lt;&lt; ", ";
          return true;
      }
      if(exploreMaze(maze, x, y - 1))
      {
          cout &lt;&lt; "left" &lt;&lt; ", ";
          return true;
      }
      if(exploreMaze(maze, x, y + 1))
      {
          cout &lt;&lt; "right" &lt;&lt; ", ";
          return true;
      }
  
      return false;
  }
  
  bool isMazeSolvable(char maze[][N])
  {
      int startX = -1, startY = -1;
  
      for(int i = 0; i &lt; N; i++)
      {
          for(int j = 0; j &lt; N; j++)
          {
              if(maze[i][j] == 'S')
                  startX = i;
                  startY = j;
          }
      }
      if(startX == -1)
          return false;
  
      return exploreMaze(maze, startX, startY);
  
  }
  
  int main()
  {
      char maze[N][N] = {"*******", " S     ", "*******", "  E    ", "*******",         
      "*******", "*******", "*******"};
      cout &lt;&lt; isMazeSolvable(maze);
      return 0;
  }
  </code></pre>
  
  <p>The array that I'm testing in main should definitely have no solution, but somehow I'm getting 1(true) as the output. Any ideas?</p>