/* * See this URL for lots of information about Picobot: * * http://www.cs.hmc.edu/~dodds/Picobot/index.html */ /* * Be sure to save this file before running! */ /* * This example zips up and down in the middle of the screen * State 0 is always the starting state */ 1 // this indicates the map we want to start with //Go west until we hit a wall. 0 **x* -> W 0 0 **W* -> X 1 //Go east until we hit a wall; back up. Head south if we can't back up. //This is one place where we can try to detect if we're in a north-south //corridor, and therefore engage the maze solver. Most of the states would //require an excessive amount of enumeration to check for the corridor case, //though. Blah. 1 *x** -> E 1 1 NEWx -> S 3 1 *Ex* -> W 2 1 xEWx -> X 6 //Engage maze solver //Head north if we can; otherwise start going the other direction. If we can't //go north *or* south, then engage the corridor solver. 2 x**S -> N 0 2 x**x -> N 0 2 N**x -> S 3 2 N**S -> X 6 //Go west until we hit a wall. Another place where we can try to solve mazes 3 **x* -> W 3 3 *xW* -> X 4 3 xEWx -> X 6 //Go east until we hit a wall; back up. Head north if we can't back up. 4 *x** -> E 4 4 *EW* -> N 0 4 *Ex* -> W 5 //Head south if we can; otherwise reverse direction. 5 ***x -> S 3 5 x**S -> N 0 //Maze-solver: use the right-hand-rule. Four states, depending on which //direction is to the right at the moment. 6 north, 7 east, 8 west, 9 south. //"Right" is North; if we have a wall to the north, then go west if we can. 6 NxWS -> E 9 //Completely stonewalled; reverse path 6 N*Wx -> S 8 //Blocked; turn left just this once 6 N*x* -> W 6 //Keep following wall 6 x*** -> N 7 //Turn right //"Right" is East; try to go north. 7 NEWx -> S 8 //U-turn 7 NEx* -> W 6 //Turn left 7 xE*x -> N 7 //Keep following 7 *x** -> E 9 //Turn right //"Right" is West; go south 8 xEWS -> N 7 //U-turn 8 *xWS -> E 9 //Turn left 8 **Wx -> S 8 //Follow 8 **x* -> W 6 //Right //"Right" is South; go east 9 NExS -> W 6 //U-turn 9 xE*S -> N 7 //Left 9 *x*S -> E 9 //Follow 9 ***x -> S 8 //Right