Project 10.1. Your task is to program robots with varyingbehaviors. The robots t
ID: 3549096 • Letter: P
Question
Project 10.1. Your task is to program robots with varyingbehaviors. The robots try to escape a maze, such as the
following:
A robot has a position and a method void move (Maze m) thatmodifies the position. Provide a common
superclass Robot whose move method does nothing. Provide subclassesRandomRobot,
RightHandRuleRobot, and MemoryRobot. Each of these robots has adifferent strategy for escaping. The
RandomRobot simply makes random moves. The RightHandRuleRobot movesaround the maze so that
it's right hand always touches a wall. The MemoryRobot remembersall positions that it has previously
occupied and never goes back to a position that it knows to be adead end.
Please Include all classes including the super class, and a tester class
Explanation / Answer
Three easy steps
1. Load in the maze.
2. Make your robot.
3. Traverse the maze in discrete steps (watching for 200 move limit or
success)
So just give your parent robot class a position, and then let it accept
class maze. (The assignment description says the parent class doesn't do
anything, so he won't actually every move.) Put the move command in a
loop, that will repeat 200 times, but exit if the robot is successful in
escaping.
The random movement robot is going to be easier to implement. You will
quickly find that you need an "is move legal" function, which you can define
in the parent class, and then keep having him move in random directions, and
find a way to double check yourself to make sure he doesn't go into or
through any walls. Whether a bad random move means you select another
direction or simply don't move is up to the assignment description, but if
given the choice (IE if not defined) then I would definitely opt in choosing
another random direction until you can move.
If it were up to me I'd have one function tell me where to move
called by another function which actually does the moving - this way it is
very easy to implement clear cut checking that you are not crossing through
any walls. See if you can get away with it. (If you are asking the teacher
though I highly suggest you don't say that someone from a newsgroup told you
to ask this question - try to make yourself sound smart, and say you have a
good reason for using another function. But make sure you know what that
reason is, and have rehearsed a few times before so you don't make an ass of
yourself!)
have yourmain function call Robot.Move(Maze)
which calls Robot.WhichDirection(maze) that returns a direction (IE up,
down, left, right) Robot.Move(Maze) will also check after a move has
occurred that there was no collision. If there was then BACK TO THE
DRAWING BOARD! HAHA! (You could get yourself in trouble doing it the way I
have done it in the past, returning +1 or -1 and 0 . . n for forward or
backward and which dimension - but this is probably the "best" way to do it
if you are ever considering making higher dimension mazes)
Load the maze, find some way
to test that that part is working. Then make a move function, which has no
intelligence yet, but make sure it works. Then the which direction, then
the is move legal.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.