mazewalker
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| mazewalker [2019/08/29 13:12] – frchris | mazewalker [2022/09/05 12:25] (current) – [MaveWalker Troubleshooting] frchris | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | Write an instruction '' | + | Write an instruction '' |
| - | {{:: | + | |
| - | Here are four of the different position changes | + | ====== Before ====== |
| + | |||
| + | {{:: | ||
| + | ====== After ====== | ||
| + | {{:: | ||
| + | |||
| + | These four different position changes is the cornerstone for the algorithm | ||
| + | |||
| + | |||
| + | <code java> | ||
| + | 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 '' | ||
| + | |||
| + | {{ :: | ||
| + | |||
| + | Once the tester shows that the four cases are handled correctly, here is a maze runner class with its own maze: | ||
| + | |||
| + | {{ :: | ||
| + | |||
| + | |||
| + | ===== Running your MazeWaker with Student Mazes ===== | ||
| + | |||
| + | Download the text file you find at [[https:// | ||
| + | <code MazeWalkerRunner.java> | ||
| + | import java.awt.Color; | ||
| + | import kareltherobot.*; | ||
| + | public class MazeWalkerRunner implements Directions | ||
| + | { | ||
| + | public static void task() | ||
| + | { | ||
| + | // change the location to where the first beeper is: | ||
| + | MazeWalker mayzie = new MazeWalker(1, | ||
| + | mayzie.pickBeeper(); | ||
| + | mayzie.escapeMaze(); | ||
| + | mayzie.turnOff(); | ||
| + | } | ||
| + | |||
| + | public static void main(String[] args) | ||
| + | { | ||
| + | World.reset(); | ||
| + | World.setDelay(1); | ||
| + | World.setBeeperColor(Color.RED); | ||
| + | // change the name to match the maze world file | ||
| + | World.readWorld(" | ||
| + | World.setVisible(); | ||
| + | task(); | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== MazeWalker Troubleshooting ===== | ||
| + | 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? | ||
| + | ====== Links ====== | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
mazewalker.1567098721.txt.gz · Last modified: 2019/08/29 13:12 by frchris