Create a public class Rat with the method
†public int move(boolean gof, boolean gor, boolean gob, boolean gol);
∑ gof is true if the rat can go forward one unit, false if that way is blocked.
∑ gor is true if the rat can go right one unit, false if that way is blocked.
∑ gof is true if the rat can go backward one unit, false if that way is blocked.
∑ gof is true if the rat can go left one unit, false if that way is blocked.
The function must return a direction that rat is to move.† The possible directions are:
††† FORWARD = 0;
††† RIGHT†† = 1;
††† BACK††† = 2;
††† LEFT††† = 3;
The rat is then moved in the specified direction.† The ratís orientation is changed if it moves left, right or backward.† If it moves back, then the rat turns 180į and is moving in the opposite direction.† Things that were previously on the right will now be on the left.
Your Rat class should have a constructor
public Rat(int size);
where size is the number of nodes along the side of a square maze.
Email your Rat.java to email@example.com by noon on Wednesday, January 28, 2009.† Your challenge is to create a rat that finds the cheese with the least number of moves.
For the second phase, your Rat class should have the method
public void reset();
This method is called after your rat program has successfully navigated through the maze.† You may assume that the last call to your move method moved your rat to the cheese.† The reset method moves that rat back to the beginning of the maze and reorients it to point to the west.† The main program will then call your move methods again to find your way through the maze.† This time your move method can use any information it learned during its first trip through the maze.
Email your updated Rat to firstname.lastname@example.org by noon on February 4, 2009.