title: BFS maze help c++
body: <p>I am attempting to make a maze-solver using a Breadth-first search, and mark the shortest path using a character '*'</p>
  
  <p>The maze is actually just a bunch of text. The maze consists of an n x n grid, consisting of "#" symbols that are walls, and periods "." representing the walkable area/paths. An 'S' denotes start, 'F' is finish.  Right now, this function does not seem to be finding the solution (it thinks it has the solution even when one is impossible).  I am checking the four neighbors, and if they are 'unfound' (-1) they are added to the queue to be processed.  </p>
  
  <p>The maze works on several mazes, but not on this one:</p>
  
  <pre><code>...###.#.... 
  ##.#...####.
  ...#.#.#....
  #.####.####.
  #F..#..#.##.
  ###.#....#S.
  #.#.####.##.
  ....#.#...#.
  .####.#.#.#.
  ........#...
  </code></pre>
  
  <p>What could be missing in my logic?</p>
  
  <pre><code>int mazeSolver(char *maze, int rows, int cols)
  {
  int start = 0;
  int finish = 0;
  for (int i=0;i&lt;rows*cols;i++) {
      if (maze[i] == 'S') { start=i; }
      if (maze[i] == 'F') { finish=i; }
  }
  if (finish==0 || start==0) { return -1; }
  
  char* bfsq;
  bfsq = new char[rows*cols]; //initialize queue array
  int head = 0;
  int tail = 0;
  bool solved = false;
  char* prd;  
  prd = new char[rows*cols]; //initialize predecessor array
  for (int i=0;i&lt;rows*cols;i++) {
      prd[i] = -1;
  }
  prd[start] = -2; //set the start location
  bfsq[tail] = start;
  tail++;
  
  int delta[] = {-cols,-1,cols,+1};   // North, West, South, East neighbors
  
  while(tail&gt;head) {
      int front = bfsq[head];
      head++;
      for (int i=0; i&lt;4; i++) {
          int neighbor = front+delta[i];
          if (neighbor/cols &lt; 0 || neighbor/cols &gt;= rows || neighbor%cols &lt; 0 || neighbor%cols &gt;= cols) {
              continue;
          }
          if (prd[neighbor] == -1 &amp;&amp; maze[neighbor]!='#') {
              prd[neighbor] = front;
              bfsq[tail] = neighbor;
              tail++;
              if (maze[neighbor] == 'F') { solved = true; }
          }   
      }
  }
  
  if (solved == true) {   
      int previous = finish;
      while (previous != start) {
          maze[previous] = '*';
          previous = prd[previous];
      }
      maze[finish] = 'F';
      return 1;
  }
  else { return 0; }
  
  delete [] prd;
  delete [] bfsq;
  
  }
  </code></pre>