|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
kareltherobot.ur_Robot
This is the root of the robot hierarchy. All robots automatically extend this class unless another is stated. All of the methods here may be overridden. A few of the methods are advanced and discussed only late in the book. The basic functionality used throughout is discussed in Chapter 2 (move, turnLeft, pickBeeper, putBeeper, turnOff). To get robots moving simultaneously you need to use threads and the run method as discussed in Chapter 8. Most of the others are for advanced concurrent robot operation similar to CSP (Communicating Sequential Processes) and implement message channels between pairs of robots.
Inner Class Summary | |
static interface |
ur_Robot.ConnectStrategy
Used so that tailored communication strategies may be developed. |
Constructor Summary | |
ur_Robot(int street,
int avenue,
kareltherobot.Direction direction,
int beepers)
Create and display a new ur_Robot on Street street, at Avenue avenue, facing Direction, with beeprs in Beeperbag. |
Method Summary | |
void |
acceptConnection(java.io.PipedOutputStream s,
ur_Robot.ConnectStrategy strat)
|
void |
acceptConnectionFrom(ur_Robot sender,
java.io.PipedOutputStream s, ur_Robot.ConnectStrategy strat)
Executed when another robot connects to the receiver. |
java.io.BufferedWriter |
connectTo(ur_Robot other,
ur_Robot.ConnectStrategy strat)
Robot connects to another robot and is listed in that other robot's sender list. |
java.lang.String |
getNextCommunication()
Robot immediately gets the next available communication. |
void |
move()
Robot moves one block forward if front is not blocked. |
void |
pickBeeper()
If robot is on a corner with a beeper it picks up one beeper. |
void |
putBeeper()
If robot has a beeper in its beeperbag it puts one on the current corner. |
void |
run()
All robots implement runnable. |
void |
send(java.io.BufferedWriter other,
java.lang.String s) Sends communication s to robot other. |
void |
showState(java.lang.String s)
Write a trace to standard output of the robot's state (position, direction...) |
protected
void |
sleep()
|
java.lang.String |
toString()
|
void |
turnLeft()
Robot turns left 90 degrees |
void |
turnOff()
Robot turns off and will accept no more instructions. |
java.lang.String |
waitForCommunication()
Robot waits if necessary for the next incoming communication. |
java.lang.String |
waitForNextCommunication()
Robot waits if necessary for incoming communication from the next sender. |
Constructor Detail |
public ur_Robot(int street, int avenue, kareltherobot.Direction direction, int beepers)
street
- The street on which the new robot will be created.avenue
- The avenue on which the new robot will be created.direction
- The direction in which it will face: North, South, East, or West from the Directions
interface.beepers
- Initial number of beepers in beeper bag (can be infinity).Method Detail |
public void turnLeft()
public void move()
public void pickBeeper()
public void putBeeper()
public void turnOff()
public java.lang.String getNextCommunication()
In the future this may be generalized to return an arbitrary Object.
public java.lang.String waitForCommunication()
In the future this may be generalized to return an arbitrary Object.
public java.lang.String waitForNextCommunication()
In the future this may be generalized to return an arbitrary Object.
public java.io.BufferedWriter connectTo(ur_Robot other, ur_Robot.ConnectStrategy strat) throws java.io.IOException
other
- The robot to connect to.
strat
- The communication strategy to use in the communication.
public void acceptConnectionFrom(ur_Robot sender, java.io.PipedOutputStream s, ur_Robot.ConnectStrategy strat) throws java.io.IOException
sender
- The robot that is connecting.
s
- The pipe overwhich the robots can communicate.
strat
- The communication strategy.
public void acceptConnection(java.io.PipedOutputStream s, ur_Robot.ConnectStrategy strat) throws java.io.IOExceptionThis is experimental and unused.
public void send(java.io.BufferedWriter other, java.lang.String s) throws java.io.IOException
other
- The robot that this one is trying to communicate
with.
s
- The communication.
In the future this may be generalized to permit an arbitrary Object to be sent.
public void run()
run
in interface java.lang.Runnable
public final java.lang.String toString()
protected void sleep()See Chpater 8.
public final void showState(java.lang.String s)
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |