Note that there are some explanatory texts on larger screens.

plurals
  1. POMaze solver looping issue java
    text
    copied!<p>So basically what I'm trying to do is creating a maze solving algorithm with the left hand rule but I'm encountering an issue that I can't seem to get passed. </p> <p>The first two codes are the ones I'm working with and the problem I'm having is that when I try to loop the if-statements it just continues to draw a straight line up instead of turning left (in this case) and THEN looping back to the beginning and drawing a line until it hits a wall again. Note that I'm aware that this aint the finished product, I just want to make sure that alteast the first left turn and the loop works correctly.</p> <pre><code>import se.lth.cs.ptdc.window.SimpleWindow; import se.lth.cs.ptdc.maze.*; public class MazeTurtle extends Turtle { protected int Maze; public MazeTurtle(SimpleWindow w, int x, int y) { super(w, x, y); } public void walk(Maze maze) { Maze m = new Maze(1); Turtle t = new Turtle(w, m.getXEntry(), m.getYEntry()); t.penDown(); while(true){ if(m.wallAtLeft(getDirection(), getX(), getY())){ t.forward(1); } if(m.wallAtLeft(getDirection(), getX(), getY())){ t.left(90); } /** The "wallInFront" could be ignored for now */ if(m.wallInFront(getDirection(), getX(), getY())) { t.left(-90); } if(m.wallInFront(getDirection(), getX(), getY())){ t.forward(1); } SimpleWindow.delay(10); } } } </code></pre> <p>Here is the the "Test" which tries to solve the maze with the given algorithm:</p> <pre><code>import se.lth.cs.ptdc.window.SimpleWindow; import se.lth.cs.ptdc.maze.*; public class MazeTest { public static void main(String args[]) { Maze m = new Maze(1); SimpleWindow w = new SimpleWindow(600, 600, "MazeTest"); MazeTurtle t = new MazeTurtle(w, m.getXEntry(), m.getYEntry()); t.penDown(); m.draw(w); t.walk(m); } } </code></pre> <p>Here is the maze class which i'm reffering to: <a href="http://pastebin.com/gxSeEc2U" rel="nofollow">http://pastebin.com/gxSeEc2U</a></p> <p>And the turtle class that I'm using: <a href="http://pastebin.com/0RqbVudn" rel="nofollow">http://pastebin.com/0RqbVudn</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload