title: Recursion with maze solver
body: <p>The project is to code a maze solver in Java using recursion and a tree (I'm using my own linked list, not exactly sure if it's a tree but I don't mind that).</p>
  
  <p>The lecturer never explains anything, so I get all my knowledge online. I'm having trouble with my recursive method, I'm not sure what to do since I can't find an example that can relate to my project</p>
  
  <p>In my linked list, I have links to the node on the right, left, bottom and top. If there is for example a wall on your right, the link would be null. I also have booleans in the linked list <code>wallRight</code>, <code>wallLeft</code>, <code>wallBottom</code> and <code>wallTop</code> to see if there is for example a wall to the right. So if there was a wall to the right, the "Right" link would be null and <code>wallRight</code> would be true.</p>
  
  <p>I also use Labels which are images, so if I landed on a spot, an image shows. I made a method that if I'm on position 1, it makes label 1 display, so in the recursive methods I use the <code>int pos</code> to know which label to display.</p>
  
  <p>Now comes the trouble with my recursive method. I have tried it two ways, but neither work. Here is both of them:</p>
  
  <pre class="lang-java prettyprint-override"><code>public boolean move(Maze rigting,int pos) // Righting = direction
  {
     if(rigting.goal == true)
         return true; //BASE CASE - tests if it is on the goal node
  
     else if(rigting.wallR != true) //checks if there is a wall on the right
     {
         pos += 1;
         move(rigting.right, pos); //moves right
  
         showLabel(pos);
         return true;
     }
  
     else if(rigting.wallD != true) //checks if there is a wall below
     {
         pos += 10;
         move(rigting.down, pos); //moves down
  
         showLabel(pos);
         return true;
     }
  
     else if(rigting.wallL != true) //checks if there is a wall on the left
     {
         pos -= 1;
         move(rigting.left, pos); //moves left
  
         showLabel(pos);
         return true;
     }
  
     else if(rigting.wallU != true) //checks if there is a wall above
     {
         pos -= 10;
         move(rigting.up, pos); //moves up
  
         showLabel(pos);
         return true;
     }
  
     return false; //I know this return is incorrect, but it won't run without one
   }
  </code></pre>
  
  <hr>
  
  <pre><code>public boolean move(Maze rigting,int pos) //Righting = direction
  {
      if(rigting.goal == true)
          return true;
  
      return (rigting.wallR != true) ? move(rigting.right, pos += 1) : false ||
      (rigting.wallD != true) ? move(rigting.down, pos += 10) : false ||
      (rigting.wallL != true) ? move(rigting.left, pos -= 1) : false ||
      (rigting.wallU != true) ? move(rigting.up, pos -= 10) : false;
  }
  </code></pre>
  
  <p>Both of these give stackoverflow exceptions...<br>
  I think my error is that, if there is a wall on the right, then the link Right is <code>null</code>. If I could somehow make it that none of the links are <code>null</code>, then I wouldn't need the booleans <code>wallRight</code> etc, but I have no idea how to implement that.</p>
  
  <p>I would really appreciate it if you could send me in the right direction! I only need to hand in the project on 10 October, so if I'm doing it completely wrong, I don't mind starting over!</p>