Note that there are some explanatory texts on larger screens.

plurals
  1. POMaze solver gets stuck in a loop at a dead-end
    primarykey
    data
    text
    <p>I'm working in a Maze solver algorithm and everything is working fine until it hits a dead-end and gets stuck in a loop, <a href="http://i.imgur.com/NYtCY.png" rel="nofollow">like this</a>. The problem seems to be that when it want to turn around there aint enough space for it so instead it makes another turn since it faces a wall in front and thus gets stuck in an endless loop.</p> <p>Here are the two codes I'm working with but the first one is the most relevant one.</p> <p><code>SimpleWindow</code> is the main window where everything gets drawn etc, and the <code>maze</code> class is the file which generates the mazes and values for example <code>wallAtLeft</code>, <code>wallInFront</code>, <code>atExit</code> (these are all boolean)</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(4); Turtle t = new Turtle(w, m.getXEntry(), m.getYEntry()); int x1 = m.getXEntry(); int y1 = m.getYEntry(); int dir = t.getDirection(); t.penDown(); while ((m.atExit(x1, y1)) == false) { if (m.wallAtLeft(dir, x1, y1) == true) { t.forward(1); SimpleWindow.delay(10); } else if (m.wallAtLeft(dir, x1, y1) == false) { t.left(90); t.forward(1); SimpleWindow.delay(10); } if (m.wallInFront(dir, x1, y1) == true) { t.left(-90); t.forward(1); SimpleWindow.delay(10); } x1 = t.getX(); y1 = t.getY(); dir = t.getDirection(); System.out.println("X: " + x1 + "Y: " + y1); } } } </code></pre> <p>Here is the program that draws everything:</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(4); 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>The maze class with descriptions if it is needed. Note that only some of the methods are needed for this. <a href="http://pastebin.com/gxSeEc2U" rel="nofollow">http://pastebin.com/gxSeEc2U</a></p> <p>This is the turtle class I'm using: <a href="http://pastebin.com/0RqbVudn" rel="nofollow">http://pastebin.com/0RqbVudn</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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