Robot Problem

N

newbie

I have the following Java problem to solve and don't know where to
start. Any help I can get would be appreciated.

I have to program robots with varying behaviors. The robots try to
escape a maze that is 9x9 where the * represents a wall and the 0
represents the starting position.

A robot has a position and a method void move(Maze m) the modifies the
position. Provide a common superclass Robot whose move nethod does
nothing. Provide subclasses RandomRobot and RightHandRuleRobot. Each of
these robots has a different strategy for escaping. The RandomRobot
simply make random moves. The RighrhandRuleRobot moves around the maze
so that its right hand always touches a wall. (A RightHandRuleRobot can
start off by going in any fixed direction until it reaches a wall and
turns into the right-hand-rule mode.)
The program will be tested by redirecting a maze file to its standard
input. A maze file is a text file that contains a 9X9 maze and the
initial robot position. For a given maze file, determine if either of
your robots can escape the maze in 200 steps or not.

Hint given: You should add a field to your RightHandRuleRobot
representing the orientation. Your RightHandRuleRobot may come back to
the same position with a different orientation.
 
L

Luc The Perverse

newbie said:
I have the following Java problem to solve and don't know where to
start. Any help I can get would be appreciated.

I have to program robots with varying behaviors. The robots try to
escape a maze that is 9x9 where the * represents a wall and the 0
represents the starting position.

A robot has a position and a method void move(Maze m) the modifies the
position. Provide a common superclass Robot whose move nethod does
nothing. Provide subclasses RandomRobot and RightHandRuleRobot. Each of
these robots has a different strategy for escaping. The RandomRobot
simply make random moves. The RighrhandRuleRobot moves around the maze
so that its right hand always touches a wall. (A RightHandRuleRobot can
start off by going in any fixed direction until it reaches a wall and
turns into the right-hand-rule mode.)
The program will be tested by redirecting a maze file to its standard
input. A maze file is a text file that contains a 9X9 maze and the
initial robot position. For a given maze file, determine if either of
your robots can escape the maze in 200 steps or not.

Hint given: You should add a field to your RightHandRuleRobot
representing the orientation. Your RightHandRuleRobot may come back to
the same position with a different orientation.


The definition of the program tells you were to start. But you are in
luck - because I am the MAZE MAN!

Do you not understand what the right hand rule maze solving algorithm is?

It sounds like you are in control of how it moves about the maze, and so you
shouldn't have any problem.

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.

It sounds to me like your teacher wants the move function to actually move
the robot. 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!)

So if I were doing it, I would have my main 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)

I always prefer a very incremental approach. 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.

Hope I helped!
 
J

jamesahart79

Does the problem specification define the maze interface, or are you
allowed to define your own?

I'm saying this because it seems like it would be easiest to define the
Maze class to read in the file (perhaps give the Maze class a
constructor with a reference to the input stream.) The maze would then
keep an internal array of which positions are walls and which are open,
and the current robot position could be stored as a pair of integers.

You could also have the maze be the class that actually moves the
robot, which (among other things) provides a logical place to ensure
that the robot didn't move through a wall.

This means a little bit of extra work when loading and printing the
result, but I think it might make things simpler in the meantime.

In short, you could define functions

constructor->Maze(File) (or whatever---not sure about the input types)
boolean Maze.move(Move m) (returns true if the move was legal, false
otherwise. If the move was not legal, the robot didn't actually move.)
boolean Maze.isLegalMove(Move m) (returns if a given move is legal but
does not move the robot)
boolean Maze.isFinished() (returns true if the robot has escaped from
the maze, false otherwise)

(Note that I am not saying you should define a class called Move; it's
just shorthand for whatever technique you decide to use to represent
direction.)

Actually, I think you can implement both algorithms using just this
interface. Neither algorithm depends on the absolute position of the
robot, so the maze can just keep track of it without the robot actually
needing to know where it actually is. Of course, if that ever changes,
you can add getter routines to Maze to change that.
 
L

Luc The Perverse

Actually, I think you can implement both algorithms using just this
interface. Neither algorithm depends on the absolute position of the
robot, so the maze can just keep track of it without the robot actually
needing to know where it actually is. Of course, if that ever changes,
you can add getter routines to Maze to change that.

I'm going to disagree with you on this point.

His assignment mandates that he have a seperate maze and robot class.

It doesn't make sense to embed the location of the robot inside the maze -
this would violate OOP principles. A maze should have a size and walls.
The robot class should hold the position, orientation etc. (In this case it
sounds like he is going to be storing an array of cells which are either
filled, or empty)
 
A

andrew.butt

For this problem you are expected to define your own interface, and the
input is passed as standard input. For example, it will be tested
using "java maze.java < maze.txt" or somethign to that extent.

The test maze will appear like so:
http://img.photobucket.com/albums/v198/xceph/maze.jpg

Whee * represents walls, and 0 is the starting position.

Thank you for any additional advice.
 
L

Luc The Perverse

For this problem you are expected to define your own interface, and the
input is passed as standard input. For example, it will be tested
using "java maze.java < maze.txt" or somethign to that extent.

The test maze will appear like so:
http://img.photobucket.com/albums/v198/xceph/maze.jpg

Whee * represents walls, and 0 is the starting position.

Thank you for any additional advice.

Do you need any additional advice? I mean - what is snagging you up?
There comes a point when you just need to sit down and do it.
 
J

jamesahart79

*************************************************
I'm going to disagree with you on this point.

His assignment mandates that he have a seperate maze and robot class.
*************************************************

You're probably right. (As a test case, imagine adding another robot.
Storing the position inside the robot would make scaling it much
easier.) So we would add a coordinate term to each of the function
calls I listed, and the internal logic is much the same.

Oh, and I must agree: Time to get started coding.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top