Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
public interface IAdvancedRobotPeer
extends IStandardRobotPeer
AdvancedRobot
and TeamRobot
.
A robot peer is the object that deals with game mechanics and rules, and
makes sure your robot abides by them.
Method Summary | |
void |
|
void |
|
List |
|
List |
|
List |
|
List |
|
File |
|
File |
|
long |
|
int |
|
List |
|
List |
|
List |
|
List |
|
List |
|
List |
|
boolean |
|
boolean |
|
boolean |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
Methods inherited from interface robocode.robotinterfaces.peer.IBasicRobotPeer | |
execute , fire , getBattleFieldHeight , getBattleFieldWidth , getBodyHeading , getBodyTurnRemaining , getCall , getDistanceRemaining , getEnergy , getGraphics , getGunCoolingRate , getGunHeading , getGunHeat , getGunTurnRemaining , getName , getNumRounds , getOthers , getRadarHeading , getRadarTurnRemaining , getRoundNum , getTime , getVelocity , getX , getY , move , setBodyColor , setBulletColor , setCall , setFire , setGunColor , setRadarColor , setScanColor , turnBody , turnGun |
Methods inherited from interface robocode.robotinterfaces.peer.IStandardRobotPeer | |
rescan , resume , setAdjustGunForBodyTurn , setAdjustRadarForBodyTurn , setAdjustRadarForGunTurn , stop , turnRadar |
public void addCustomEvent(Condition condition)
Registers a custom event to be called when a condition is met. When you are finished with your condition or just want to remove it you must callremoveCustomEvent(Condition)
. Example:// Create the condition for our custom event Condition triggerHitCondition = new Condition("triggerhit") { public boolean test() { return (getEnergy() <= trigger); }; } // Add our custom event based on our condition addCustomEvent(triggerHitCondition);
- Parameters:
condition
- the condition that must be met.
- See Also:
Condition
,removeCustomEvent(Condition)
public void clearAllEvents()
Clears out any pending events in the robot's event queue immediately.
- See Also:
getAllEvents()
public ListgetAllEvents()
Returns a vector containing all events currently in the robot's queue. You might, for example, call this while processing another event. Example:for (Event event : getAllEvents()) { if (event instanceof HitRobotEvent) { // do something with the event } else if (event instanceof HitByBulletEvent) { // do something with the event } }
- Returns:
- a vector containing all events currently in the robot's queue
public ListgetBulletHitBulletEvents()
Returns a vector containing all BulletHitBulletEvents currently in the robot's queue. You might, for example, call this while processing another event. Example:for (BulletHitBulletEvent event : getBulletHitBulletEvents()) { // do something with the event }
- Returns:
- a vector containing all BulletHitBulletEvents currently in the robot's queue
public ListgetBulletHitEvents()
Returns a vector containing all BulletHitEvents currently in the robot's queue. You might, for example, call this while processing another event. Example:for (BulletHitEvent event: getBulletHitEvents()) { // do something with the event }
- Returns:
- a vector containing all BulletHitEvents currently in the robot's queue
public ListgetBulletMissedEvents()
Returns a vector containing all BulletMissedEvents currently in the robot's queue. You might, for example, call this while processing another event. Example:for (BulletMissedEvent event : getBulletMissedEvents()) { // do something with the event }
- Returns:
- a vector containing all BulletMissedEvents currently in the robot's queue
public File getDataDirectory()
Returns a file representing a data directory for the robot, which can be written to usingRobocodeFileOutputStream
orRobocodeFileWriter
. The system will automatically create the directory for you, so you do not need to create it by yourself.
- Returns:
- a file representing the data directory for your robot
public File getDataFile(String filename)
Returns a file in your data directory that you can write to usingRobocodeFileOutputStream
orRobocodeFileWriter
. The system will automatically create the directory for you, so you do not need to create it by yourself. Please notice that the max. size of your data file is set to 200000 (~195 KB). See thesample.SittingDuck
to see an example of how to use this method.
- Parameters:
filename
- the file name of the data file for your robot
- Returns:
- a file representing the data file for your robot
public long getDataQuotaAvailable()
Returns the data quota available in your data directory, i.e. the amount of bytes left in the data directory for the robot.
- Returns:
- the amount of bytes left in the robot's data directory
- See Also:
getDataDirectory()
,getDataFile(String)
public int getEventPriority(String eventClass)
Returns the current priority of a class of events. An event priority is a value from 0 - 99. The higher value, the higher priority. Example:int myHitRobotPriority = getEventPriority("HitRobotEvent");The default priorities are, from highest to lowest:BattleEndedEvent
: 100 (reserved)WinEvent
: 100 (reserved)SkippedTurnEvent
: 100 (reserved)StatusEvent
: 99 Key and mouse events: 98CustomEvent
: 80 (default value)MessageEvent
: 75RobotDeathEvent
: 70BulletMissedEvent
: 60BulletHitBulletEvent
: 55BulletHitEvent
: 50HitByBulletEvent
: 40HitWallEvent
: 30HitRobotEvent
: 20ScannedRobotEvent
: 10PaintEvent
: 5DeathEvent
: -1 (reserved)
- Parameters:
eventClass
- the name of the event class (string)
- Returns:
- the current priority of a class of events
- See Also:
setEventPriority(String,int)
public ListgetHitByBulletEvents()
Returns a vector containing all HitByBulletEvents currently in the robot's queue. You might, for example, call this while processing another event. Example:for (HitByBulletEvent event : getHitByBulletEvents()) { // do something with the event }
- Returns:
- a vector containing all HitByBulletEvents currently in the robot's queue
public ListgetHitRobotEvents()
Returns a vector containing all HitRobotEvents currently in the robot's queue. You might, for example, call this while processing another event. Example:for (HitRobotEvent event : getHitRobotEvents()) { // do something with the event }
- Returns:
- a vector containing all HitRobotEvents currently in the robot's queue
- See Also:
onHitRobot(HitRobotEvent)
,HitRobotEvent
,getAllEvents()
public ListgetHitWallEvents()
Returns a vector containing all HitWallEvents currently in the robot's queue. You might, for example, call this while processing another event. Example:for (HitWallEvent event : getHitWallEvents()) { // do something with the event }
- Returns:
- a vector containing all HitWallEvents currently in the robot's queue
- See Also:
onHitWall(HitWallEvent)
,HitWallEvent
,getAllEvents()
public ListgetRobotDeathEvents()
Returns a vector containing all RobotDeathEvents currently in the robot's queue. You might, for example, call this while processing another event. Example:for (RobotDeathEvent event : getRobotDeathEvents()) { // do something with the event }
- Returns:
- a vector containing all RobotDeathEvents currently in the robot's queue
public ListgetScannedRobotEvents()
Returns a vector containing all ScannedRobotEvents currently in the robot's queue. You might, for example, call this while processing another event. Example:for (ScannedRobotEvent event : getScannedRobotEvents()) { // do something with the event }
- Returns:
- a vector containing all ScannedRobotEvents currently in the robot's queue
public ListgetStatusEvents()
Returns a vector containing all StatusEvents currently in the robot's queue. You might, for example, call this while processing another event. Example:for (StatusEvent event : getStatusEvents()) { // do something with the event }
- Returns:
- a vector containing all StatusEvents currently in the robot's queue
- Since:
- 1.6.1
- See Also:
onStatus(StatusEvent)
,StatusEvent
,getAllEvents()
public boolean isAdjustGunForBodyTurn()
Checks if the gun is set to adjust for the robot turning, i.e. to turn independent from the robot's body turn. This call returnstrue
if the gun is set to turn independent of the turn of the robot's body. Otherwise,false
is returned, meaning that the gun is set to turn with the robot's body turn.
- Returns:
true
if the gun is set to turn independent of the robot turning;false
if the gun is set to turn with the robot turning
- See Also:
setAdjustGunForBodyTurn(boolean)
,isAdjustRadarForBodyTurn()
,isAdjustRadarForGunTurn()
public boolean isAdjustRadarForBodyTurn()
Checks if the radar is set to adjust for the gun turning, i.e. to turn independent from the gun's turn. This call returnstrue
if the radar is set to turn independent of the turn of the gun. Otherwise,false
is returned, meaning that the radar is set to turn with the gun's turn.
- Returns:
true
if the radar is set to turn independent of the gun turning;false
if the radar is set to turn with the gun turning
- See Also:
setAdjustRadarForGunTurn(boolean)
,isAdjustGunForBodyTurn()
,isAdjustRadarForBodyTurn()
public boolean isAdjustRadarForGunTurn()
Checks if the radar is set to adjust for the robot turning, i.e. to turn independent from the robot's body turn. This call returnstrue
if the radar is set to turn independent of the turn of the robot. Otherwise,false
is returned, meaning that the radar is set to turn with the robot's turn.
- Returns:
true
if the radar is set to turn independent of the robot turning;false
if the radar is set to turn with the robot turning
- See Also:
setAdjustRadarForBodyTurn(boolean)
,isAdjustGunForBodyTurn()
,isAdjustRadarForGunTurn()
public void removeCustomEvent(Condition condition)
Removes a custom event that was previously added by callingaddCustomEvent(Condition)
. Example:// Create the condition for our custom event Condition triggerHitCondition = new Condition("triggerhit") { public boolean test() { return (getEnergy() <= trigger); }; } // Add our custom event based on our condition addCustomEvent(triggerHitCondition); ... do something with your robot ... // Remove the custom event based on our condition removeCustomEvent(triggerHitCondition);
- Parameters:
condition
- the condition that was previous added and that must be removed now.
- See Also:
Condition
,addCustomEvent(Condition)
public void setEventPriority(String eventClass, int priority)
Sets the priority of a class of events. Events are sent to the onXXX handlers in order of priority. Higher priority events can interrupt lower priority events. For events with the same priority, newer events are always sent first. Valid priorities are 0 - 99, where 100 is reserved and 80 is the default priority. Example:setEventPriority("RobotDeathEvent", 15);The default priorities are, from highest to lowest:Note that you cannot change the priority for events with the special priority value -1 or 100 (reserved) as these event are system events. Also note that you cannot change the priority of CustomEvent. Instead you must change the priority of the condition(s) for your custom event(s).BattleEndedEvent
: 100 (reserved)WinEvent
: 100 (reserved)SkippedTurnEvent
: 100 (reserved)StatusEvent
: 99 Key and mouse events: 98CustomEvent
: 80 (default value)MessageEvent
: 75RobotDeathEvent
: 70BulletMissedEvent
: 60BulletHitBulletEvent
: 55BulletHitEvent
: 50HitByBulletEvent
: 40HitWallEvent
: 30HitRobotEvent
: 20ScannedRobotEvent
: 10PaintEvent
: 5DeathEvent
: -1 (reserved)
- Parameters:
eventClass
- the name of the event class (string) to set the priority forpriority
- the new priority for that event class
- Since:
- 1.5, the priority of DeathEvent was changed from 100 to -1 in order to let robots process pending events on its event queue before it dies. When the robot dies, it will not be able to process events.
public void setInterruptible(boolean interruptible)
Call this during an event handler to allow new events of the same priority to restart the event handler. Example:public void onScannedRobot(ScannedRobotEvent e) { fire(1); setInterruptible(true); move(100); // If you see a robot while moving ahead, // this handler will start from the top // Without setInterruptible(true), we wouldn't // receive scan events at all! // We'll only get here if we don't see a robot during the move. getOut().println("Ok, I can't see anyone"); }
- Parameters:
interruptible
-true
if the event handler should be interrupted if new events of the same priority occurs;false
otherwise
public void setMaxTurnRate(double newMaxTurnRate)
Sets the maximum turn rate of the robot measured in degrees if the robot should turn slower thanRules.MAX_TURN_RATE
(10 degress/turn).
- Parameters:
newMaxTurnRate
- the new maximum turn rate of the robot measured in degrees. Valid values are 0 -Rules.MAX_TURN_RATE
public void setMaxVelocity(double newMaxVelocity)
Sets the maximum velocity of the robot measured in pixels/turn if the robot should move slower thanRules.MAX_VELOCITY
(8 pixels/turn).
- Parameters:
newMaxVelocity
- the new maximum turn rate of the robot measured in pixels/turn. Valid values are 0 -Rules.MAX_VELOCITY
- See Also:
move(double)
,setMove(double)
,setMaxTurnRate(double)
public void setMove(double distance)
Sets the robot to move forward or backward by distance measured in pixels when the next execution takes place. This call returns immediately, and will not execute until you callexecute()
or take an action that executes. Note that both positive and negative values can be given as input, where positive values means that the robot is set to move forward, and negative values means that the robot is set to move backward. If 0 is given as input, the robot will stop its movement, but will have to decelerate till it stands still, and will thus not be able to stop its movement immediately, but eventually. Example:// Set the robot to move 50 pixels forward setMove(50); // Set the robot to move 100 pixels backward // (overrides the previous order) setMove(-100); ... // Executes the last setMove() execute();
- Parameters:
distance
- the distance to move measured in pixels. Ifdistance
> 0 the robot is set to move forward. Ifdistance
<320 the robot is set to move backward. Ifdistance
= 0 the robot is set to stop its movement.
public void setResume()
Sets the robot to resume the movement stopped bystop(boolean)
orsetStop(boolean)
, if any. This call returns immediately, and will not execute until you callexecute()
or take an action that executes.
- See Also:
resume()
,stop(boolean)
,setStop(boolean)
,execute()
public void setStop(boolean overwrite)
This call is identical tostop(boolean)
, but returns immediately, and will not execute until you callexecute()
or take an action that executes. If there is already movement saved from a previous stop, you can overwrite it by callingsetStop(true)
.
- Parameters:
overwrite
-true
if the movement saved from a previous stop should be overwritten;false
otherwise.
- See Also:
stop(boolean)
,resume()
,setResume()
,execute()
public void setTurnBody(double radians)
Sets the robot's body to turn right or left by radians when the next execution takes place. This call returns immediately, and will not execute until you callexecute()
or take an action that executes. Note that both positive and negative values can be given as input, where positive values means that the robot's body is set to turn right, and negative values means that the robot's body is set to turn left. If 0 is given as input, the robot's body will stop turning. Example:// Set the robot's body to turn 180 degrees to the right setTurnBody(Math.PI); // Set the robot's body to turn 90 degrees to the left instead of right // (overrides the previous order) setTurnBody(-Math.PI / 2); ... // Executes the last setTurnBody() execute();
- Parameters:
radians
- the amount of radians to turn the robot's body. Ifradians
> 0 the robot's body is set to turn right. Ifradians
<320 the robot's body is set to turn left. Ifradians
= 0 the robot's body is set to stop turning.
public void setTurnGun(double radians)
Sets the robot's gun to turn right or left by radians when the next execution takes place. This call returns immediately, and will not execute until you callexecute()
or take an action that executes. Note that both positive and negative values can be given as input, where positive values means that the robot's gun is set to turn right, and negative values means that the robot's gun is set to turn left. If 0 is given as input, the robot's gun will stop turning. Example:// Set the robot's gun to turn 180 degrees to the right setTurnGun(Math.PI); // Set the robot's gun to turn 90 degrees to the left instead of right // (overrides the previous order) setTurnGun(-Math.PI / 2); ... // Executes the last setTurnFun() execute();
- Parameters:
radians
- the amount of radians to turn the robot's gun. Ifradians
> 0 the robot's gun is set to turn right. Ifradians
<320 the robot's gun is set to turn left. Ifradians
= 0 the robot's gun is set to stop turning.
public void setTurnRadar(double radians)
Sets the robot's radar to turn right or left by radians when the next execution takes place. This call returns immediately, and will not execute until you callexecute()
or take an action that executes. Note that both positive and negative values can be given as input, where positive values means that the robot's radar is set to turn right, and negative values means that the robot's radar is set to turn left. If 0 is given as input, the robot's radar will stop turning. Example:// Set the robot's radar to turn 180 degrees to the right setTurnRadar(Math.PI); // Set the robot's radar to turn 90 degrees to the left instead of right // (overrides the previous order) setTurnRadar(-Math.PI / 2); ... // Executes the last setTurnRadar() execute();
- Parameters:
radians
- the amount of radians to turn the robot's radar. Ifradians
> 0 the robot's radar is set to turn right. Ifradians
<320 the robot's radar is set to turn left. Ifradians
= 0 the robot's radar is set to stop turning.
public void waitFor(Condition condition)
Does not return until a condition is met, i.e. when aCondition.test()
returnstrue
. This call executes immediately. See thesample.Crazy
robot for how this method can be used.
- Parameters:
condition
- the condition that must be met before this call returns
- See Also:
Condition
,Condition.test()