A remote controlled
Robot is to explore a maze. The maze if composed
of
walls, and inner empty space. The maze configuration is encoded in file
maze.txt as lines of 'w' characters representing walls, 'o'
characters
representing space outside the maze, and empty space in the maze
represented by
blanks. The configuration of the maze becomes known to the robot as it
discovers it by looking. The robot understands the commands (letter
case is
irrelevant):
a.
Look, coded with an 'l', makes
the robot answer with a 9-character
String from the set 'w' (wall), ' ' (blank for door – empty space), or 'o' (out)
depending on what is sees on the nine
cells which surround it. The robot always reports as the first sight
the
contents of the cell in front of it and then looks around clockwise. Remoty is
short-sighted, i.e. it does not see farther
than one cell.
b.
Turn direction, coded 't', which causes the robot to turn 90o
to the left ('L') or right ('R');
c.
Step, coded with an 's', which
makes the robot go one cell in its
current direction. If it cannot move, then the command has no effect.
Draw the class
diagram and write Java code to simulate
the discovery of the maze by the robot. The commands are given to the
robot via
System.in. After each command you should print a maze
snapshot as known to the robot, using the same representation as the
one in the
input file.
Robot commands are given
as one or two letters.
Example maze.txt. Robot
is marked with letter
R (each cell is
represented by one character):
oooooooooooooooooooooooooooooooo
owwwwwwwwwwwwwwwwwwwwwwwwwwwwwwo
o
w
wo
owwwwwwwww w
wwwwwwwwwwwwwwww wo
ow
w w w
w wo
ow
w w w w
w w wo
ow
w w w wwwwwwwwwwww w wo
ow
w
w
w wo
owwwwwwwwwwwwwRwwwwwwwwwwwwwwwwo
oooooooooooooooooooooooooooooooo
Example commands:
l
// would return " woooww"
s
l
// would return " w w www"
s
l
// would return " ww www"
s
l
// would return " ww www"
s
l
// would return "ww w www"
t R
l
// would return " w wwwww"
s
After these commands the
part
of the world known to the robot (i.e. the snapshot of the known maze)
would be:
www
wR
w w
w w
w
w w
ooo