Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SolveMaze
- {
- public static void main(String[] args)
- {
- Maze m=new Maze();
- char facingeast;
- char facingnorth;
- char facingsouth;
- char facingwest;
- char CurrentDirectionFacing=facingeast;
- while(m.goalIsNotReached()) // continue until goal is reached
- {
- while (CurrentDirectionFacing==facingnorth)
- {
- {
- if(m.wallPresent(Maze.EAST)) //if there is a wall to right check wall in front
- {
- m.wallPresent(Maze.NORTH); // check for wall in front
- }
- else
- {
- m.moveEast(); // no wall to the right.. move right
- CurrentDirectionFacing=facingeast;
- break;
- }
- }
- {
- if(m.wallPresent(Maze.NORTH)) // check if wall in front
- {
- m.wallPresent(Maze.WEST); // wall in front. check wall to left
- }
- else
- {
- m.moveNorth(); // no wall in front move forward
- CurrentDirectionFacing=facingnorth;
- break;
- }
- }
- {
- if(m.wallPresent(Maze.WEST)) // check wall to left
- {
- m.moveSouth(); // wall to left means dead end, turn around go other direction
- CurrentDirectionFacing=facingsouth;
- break;
- }
- else
- {
- m.moveWest();
- CurrentDirectionFacing=facingwest;
- break;
- }
- }
- }
- while (CurrentDirectionFacing==facingeast)
- {
- {
- if(m.wallPresent(Maze.SOUTH)) //if there is a wall to right check wall in front
- {
- m.wallPresent(Maze.EAST); // check for wall in front
- }
- else
- {
- m.moveSouth(); // no wall to the right.. move right
- CurrentDirectionFacing=facingsouth;
- break;
- }
- }
- {
- if(m.wallPresent(Maze.EAST)) // check if wall in front
- {
- m.wallPresent(Maze.NORTH); // wall in front. check wall to left
- }
- else
- {
- m.moveEast(); // no wall in front move forward
- CurrentDirectionFacing=facingeast;
- break;
- }
- }
- {
- if(m.wallPresent(Maze.NORTH)) // check wall to left
- {
- m.moveWest(); // wall to left means dead end, turn around go other direction
- CurrentDirectionFacing=facingwest;
- break;
- }
- else
- {
- m.moveNorth();
- CurrentDirectionFacing=facingnorth;
- break;
- }
- }
- }
- while (CurrentDirectionFacing==facingsouth)
- {
- {
- if(m.wallPresent(Maze.WEST)) //if there is a wall to right check wall in front
- {
- m.wallPresent(Maze.SOUTH); // check for wall in front
- }
- else
- {
- m.moveWest(); // no wall to the right.. move right
- CurrentDirectionFacing=facingwest;
- break;
- }
- }
- {
- if(m.wallPresent(Maze.SOUTH)) // check if wall in front
- {
- m.wallPresent(Maze.EAST); // wall in front. check wall to left
- }
- else
- {
- m.moveSouth(); // no wall in front move forward
- CurrentDirectionFacing=facingsouth;
- break;
- }
- }
- {
- if(m.wallPresent(Maze.EAST)) // check wall to left
- {
- m.moveEast(); // wall to left means dead end, turn around go other direction
- CurrentDirectionFacing=facingeast;
- break;
- }
- else
- {
- m.moveEast();
- CurrentDirectionFacing=facingeast;
- break;
- }
- }
- }
- while (CurrentDirectionFacing==facingwest)
- {
- {
- if(m.wallPresent(Maze.NORTH)) //if there is a wall to right check wall in front
- {
- m.wallPresent(Maze.WEST); // check for wall in front
- }
- else
- {
- m.moveNorth(); // no wall to the right.. move right
- CurrentDirectionFacing=facingnorth;
- break;
- }
- }
- {
- if(m.wallPresent(Maze.WEST)) // check if wall in front
- {
- m.wallPresent(Maze.SOUTH); // wall in front. check wall to left
- }
- else
- {
- m.moveWest(); // no wall in front move forward
- CurrentDirectionFacing=facingwest;
- break;
- }
- }
- {
- if(m.wallPresent(Maze.SOUTH)) // check wall to left
- {
- m.moveEast(); // wall to left means dead end, turn around go other direction
- CurrentDirectionFacing=facingeast;
- break;
- }
- else
- {
- m.moveSouth();
- CurrentDirectionFacing=facingsouth;
- break;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement