title: Solving a Maze Using Queue in Java
body: <p>My homework is to determine if a maze is solvable of not using Queue. If it is, print the path. I can get Queue to get to the end but it says it's unsolvable. When actually it is. If I change the Final check if Statement to:</p>
  
  <pre><code>if (queue.isEmpty())
      {
          System.out.println("The maze is solvable!");
      }
  else
      {
          System.out.println("The maze is unsolvable!");
      }
  </code></pre>
  
  <p>Then it says it is solvable, but then when I try another maze that isn't solvable it says it is solvable. Not sure where I'm going wrong. </p>
  
  <p>I have a separate Point class that defines the Points and right, left, above and below positions. I have to use Point (0,0) to mark the start and Point (row-1,col-1) to mark the goal.</p>
  
  <p>Let me know if you need more code. It is searching a char 2D array.</p>
  
  <p><strong>maze1.txt - (First Line Defines the # of Rows and Columns) - Is Solvable</strong></p>
  
  <pre><code>7 12
  ..+.+.++++++
  .++...++...+
  ..++.....+.+
  +.+..++.+..+
  +...++....++
  +.+++..++..+
  ++++++++++..
  </code></pre>
  
  <p><strong>Says it's unsolvable</strong></p>
  
  <pre><code>    QueueMaze
  The maze is unsolvable!
  p p + p + p + + + + + + 
  p + + p p p + + p p p + 
  p p + + p p p p p + p + 
  + p + p p + + p + p p + 
  + p p p + + p p p p + + 
  + p + + + p p + + p p + 
  + + + + + + + + + + p . 
  </code></pre>
  
  <p><strong>mMethod for solving the Maze</strong></p>
  
  <pre><code>public void queueMaze() {
  
  char[][] storedMaze = copy(); 
  
  LinkedList&lt;Point&gt; queue = new LinkedList&lt;Point&gt;();
      int count = 0;
      Point start = new Point(0,0);
      Point cur, end, above, right, left, below;
  
      Boolean solved = false;
  
  queue.add(start); 
  
  while (!queue.isEmpty())
      {
      //Store the first element position 0 in cur
          cur = queue.removeFirst();
          //System.out.println(cur.toString());
  
          //compare cur's points to the isEnd points
          //(row-1, col-1) if it is the end, break out
          //of the While
          if (isEnd(cur) &amp;&amp; isSafe(cur))
          {
              //System.out.println("cur's final : " + cur.toString());
              end = cur;
              break;
          }
  
          //mark cur as visited with a P
      markVisited(cur, P);
  
          //check the position above cur to see if it is
          //
      right = cur.getRight(); 
      if (inBounds(right) &amp;&amp; isSafe(right))
          {
              queue.add(right);
          }
  
          below = cur.getBelow(); 
      if (inBounds(below) &amp;&amp; isSafe(below))
          {
              queue.add(below);
          }
  
          left = cur.getLeft(); 
      if (inBounds(left) &amp;&amp; isSafe(left))
          {
              queue.add(left);
          }
  
          above = cur.getAbove(); 
      if (inBounds(above) &amp;&amp; isSafe(above))
          {
              queue.add(above);
          }
  
  }//while
  //System.out.println("The queue size is: " + queue.size());
  
      if (!queue.isEmpty())
      {
          System.out.println("The maze is solvable!");
      }
  else
      {
          System.out.println("The maze is unsolvable!");
      }
  
  print();
  
  returnMaze(storedMaze);
  }
  </code></pre>