mazewalker
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
mazewalker [2019/08/29 23:24] – frchris | mazewalker [2019/08/29 23:59] – frchris | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | Write an instruction '' | + | Write an instruction '' |
- | {{:: | + | |
- | Here are four of the different position changes that the robot must be able to make. This instruction is the cornerstone for the program that directs a robot to escape from a maze. It isn't the most efficient algorithm, and it won't work on mazes that have islands (Can you imagine why? | + | ====== Before ====== |
- | {{ ::mazewalker.java |MazeWalker.java}} | + | {{::turnrightbefore.png|}} |
+ | ====== After ====== | ||
+ | {{:: | ||
+ | |||
+ | These four different position changes is the cornerstone for the algorithm that directs a robot to escape from a maze simply by following the right wall. It isn't the most efficient algorithm, and it won't work on mazes that have islands (Can you imagine why? | ||
+ | |||
+ | |||
+ | < | ||
+ | import kareltherobot.*; | ||
+ | public class MazeWalker extends Robot | ||
+ | { | ||
+ | |||
+ | public MazeWalker(int street, int avenue, | ||
+ | | ||
+ | { | ||
+ | super(street, | ||
+ | |||
+ | } | ||
+ | /** | ||
+ | * This is an algorithm to run a maze. It isn't the fastest method, | ||
+ | * and won't work if the maze has any islands (Can you imagine why?) | ||
+ | * Would it be better to follow the leftWalls? | ||
+ | */ | ||
+ | public void escapeMaze() { | ||
+ | while (! nextToABeeper() ) | ||
+ | followRightWall(); | ||
+ | } | ||
+ | /** | ||
+ | * This will move the Robot according to the diagram | ||
+ | * above. | ||
+ | */ | ||
+ | public void followRightWall() | ||
+ | { | ||
+ | |||
+ | } | ||
+ | |||
+ | public void turnRight() { | ||
+ | for (int i=0; i<3; i++) | ||
+ | turnLeft(); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | First use the '' | ||
{{ :: | {{ :: | ||
Line 11: | Line 55: | ||
{{ :: | {{ :: | ||
+ | |||
+ | Hints: | ||
+ | * Case One check: is the front clear? | ||
+ | * Case 2,3,4 you can move | ||
+ | * Case 2 versus case 3,4: is there a wall on the right? | ||
+ | * In case 3 and 4 you can move to the right. | ||
+ | * Case 3 versus case 4: is there a wall on the right? |
mazewalker.txt · Last modified: 2022/09/05 12:25 by frchris