|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface IAdvancedRobotPeer
The advanced robot peer for advanced robot types like
AdvancedRobot
and TeamRobot
.
IBasicRobotPeer
,
IStandardRobotPeer
,
ITeamRobotPeer
,
IJuniorRobotPeer
Method Summary | |
---|---|
void |
addCustomEvent(Condition condition)
Registers a custom event to be called when a condition is met. |
void |
clearAllEvents()
Clears out any pending events in the robot's event queue immediately. |
List<Event> |
getAllEvents()
Returns a vector containing all events currently in the robot's queue. |
List<BulletHitBulletEvent> |
getBulletHitBulletEvents()
Returns a vector containing all BulletHitBulletEvents currently in the robot's queue. |
List<BulletHitEvent> |
getBulletHitEvents()
Returns a vector containing all BulletHitEvents currently in the robot's queue. |
List<BulletMissedEvent> |
getBulletMissedEvents()
Returns a vector containing all BulletMissedEvents currently in the robot's queue. |
File |
getDataDirectory()
Returns a file representing a data directory for the robot, which can be written to using RobocodeFileOutputStream or
RobocodeFileWriter . |
File |
getDataFile(String filename)
Returns a file in your data directory that you can write to using RobocodeFileOutputStream or RobocodeFileWriter . |
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. |
int |
getEventPriority(String eventClass)
Returns the current priority of a class of events. |
List<HitByBulletEvent> |
getHitByBulletEvents()
Returns a vector containing all HitByBulletEvents currently in the robot's queue. |
List<HitRobotEvent> |
getHitRobotEvents()
Returns a vector containing all HitRobotEvents currently in the robot's queue. |
List<HitWallEvent> |
getHitWallEvents()
Returns a vector containing all HitWallEvents currently in the robot's queue. |
List<RobotDeathEvent> |
getRobotDeathEvents()
Returns a vector containing all RobotDeathEvents currently in the robot's queue. |
List<ScannedRobotEvent> |
getScannedRobotEvents()
Returns a vector containing all ScannedRobotEvents currently in the robot's queue. |
List<StatusEvent> |
getStatusEvents()
Returns a vector containing all StatusEvents currently in the robot's queue. |
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. |
boolean |
isAdjustRadarForBodyTurn()
Checks if the radar is set to adjust for the gun turning, i.e. to turn independent from the gun's turn. |
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. |
void |
removeCustomEvent(Condition condition)
Removes a custom event that was previously added by calling addCustomEvent(Condition) . |
void |
setEventPriority(String eventClass,
int priority)
Sets the priority of a class of events. |
void |
setInterruptible(boolean interruptible)
Call this during an event handler to allow new events of the same priority to restart the event handler. |
void |
setMaxTurnRate(double newMaxTurnRate)
Sets the maximum turn rate of the robot measured in degrees if the robot should turn slower than Rules.MAX_TURN_RATE (10 degress/turn). |
void |
setMaxVelocity(double newMaxVelocity)
Sets the maximum velocity of the robot measured in pixels/turn if the robot should move slower than Rules.MAX_VELOCITY (8 pixels/turn). |
void |
setMove(double distance)
Sets the robot to move forward or backward by distance measured in pixels when the next execution takes place. |
void |
setResume()
Sets the robot to resume the movement stopped by stop(boolean) or
setStop(boolean) , if any. |
void |
setStop(boolean overwrite)
This call is identical to stop(boolean) , but returns immediately, and will not execute until you
call execute() or take an action that executes. |
void |
setTurnBody(double radians)
Sets the robot's body to turn right or left by radians when the next execution takes place. |
void |
setTurnGun(double radians)
Sets the robot's gun to turn right or left by radians when the next execution takes place. |
void |
setTurnRadar(double radians)
Sets the robot's radar to turn right or left by radians when the next execution takes place. |
void |
waitFor(Condition condition)
Does not return until a condition is met, i.e. when a Condition.test() returns true . |
Methods inherited from interface robocode.robotinterfaces.peer.IStandardRobotPeer |
---|
resume, setAdjustGunForBodyTurn, setAdjustRadarForBodyTurn, setAdjustRadarForGunTurn, stop, turnRadar |
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, rescan, setBodyColor, setBulletColor, setCall, setDebugProperty, setFire, setGunColor, setRadarColor, setScanColor, turnBody, turnGun |
Method Detail |
---|
boolean isAdjustGunForBodyTurn()
true
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.
true
if the gun is set to turn independent of the robot
turning; false
if the gun is set to turn with the robot
turningsetAdjustGunForBodyTurn(boolean)
,
isAdjustRadarForBodyTurn()
,
isAdjustRadarForGunTurn()
boolean isAdjustRadarForGunTurn()
true
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.
true
if the radar is set to turn independent of the robot
turning; false
if the radar is set to turn with the robot
turningsetAdjustRadarForBodyTurn(boolean)
,
isAdjustGunForBodyTurn()
,
isAdjustRadarForGunTurn()
boolean isAdjustRadarForBodyTurn()
true
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.
true
if the radar is set to turn independent of the gun
turning; false
if the radar is set to turn with the gun
turningsetAdjustRadarForGunTurn(boolean)
,
isAdjustGunForBodyTurn()
,
isAdjustRadarForBodyTurn()
void setStop(boolean overwrite)
stop(boolean)
, but returns immediately, and will not execute until you
call execute()
or take an action that executes.
If there is already movement saved from a previous stop, you can
overwrite it by calling setStop(true)
.
overwrite
- true
if the movement saved from a previous stop
should be overwritten; false
otherwise.stop(boolean)
,
resume()
,
setResume()
,
execute()
void setResume()
stop(boolean)
or
setStop(boolean)
, if any.
This call returns immediately, and will not execute until you call
execute()
or take an action that executes.
resume()
,
stop(boolean)
,
setStop(boolean)
,
execute()
void setMove(double distance)
execute()
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();
distance
- the distance to move measured in pixels.
If distance
> 0 the robot is set to move forward.
If distance
< 0 the robot is set to move backward.
If distance
= 0 the robot is set to stop its movement.move(double)
,
setMaxVelocity(double)
,
setTurnBody(double)
,
setTurnGun(double)
,
setTurnRadar(double)
void setTurnBody(double radians)
execute()
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();
radians
- the amount of radians to turn the robot's body.
If radians
> 0 the robot's body is set to turn right.
If radians
< 0 the robot's body is set to turn left.
If radians
= 0 the robot's body is set to stop turning.turnBody(double)
,
setTurnGun(double)
,
setTurnRadar(double)
,
setMaxTurnRate(double)
,
setMove(double)
void setTurnGun(double radians)
execute()
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();
radians
- the amount of radians to turn the robot's gun.
If radians
> 0 the robot's gun is set to turn right.
If radians
< 0 the robot's gun is set to turn left.
If radians
= 0 the robot's gun is set to stop turning.turnGun(double)
,
setTurnBody(double)
,
setTurnRadar(double)
,
setMove(double)
void setTurnRadar(double radians)
execute()
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();
radians
- the amount of radians to turn the robot's radar.
If radians
> 0 the robot's radar is set to turn right.
If radians
< 0 the robot's radar is set to turn left.
If radians
= 0 the robot's radar is set to stop turning.turnRadar(double)
,
setTurnBody(double)
,
setTurnGun(double)
,
setMove(double)
void setMaxTurnRate(double newMaxTurnRate)
Rules.MAX_TURN_RATE
(10 degress/turn).
newMaxTurnRate
- the new maximum turn rate of the robot measured in
degrees. Valid values are 0 - Rules.MAX_TURN_RATE
turnBody(double)
,
setTurnBody(double)
,
setMaxVelocity(double)
void setMaxVelocity(double newMaxVelocity)
Rules.MAX_VELOCITY
(8 pixels/turn).
newMaxVelocity
- the new maximum turn rate of the robot measured in
pixels/turn. Valid values are 0 - Rules.MAX_VELOCITY
move(double)
,
setMove(double)
,
setMaxTurnRate(double)
void waitFor(Condition condition)
Condition.test()
returns true
.
This call executes immediately.
See the sample.Crazy
robot for how this method can be used.
condition
- the condition that must be met before this call returnsCondition
,
Condition.test()
void setInterruptible(boolean interruptible)
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"); }
interruptible
- true
if the event handler should be
interrupted if new events of the same priority occurs; false
otherwisesetEventPriority(String, int)
,
onScannedRobot(ScannedRobotEvent)
void setEventPriority(String eventClass, int priority)
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).RoundEndedEvent
: 100 (reserved)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)
eventClass
- the name of the event class (string) to set the
priority forpriority
- the new priority for that event classgetEventPriority(String)
,
setInterruptible(boolean)
int getEventPriority(String eventClass)
int myHitRobotPriority = getEventPriority("HitRobotEvent");The default priorities are, from highest to lowest:
RoundEndedEvent
: 100 (reserved)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)
eventClass
- the name of the event class (string)
setEventPriority(String, int)
void addCustomEvent(Condition condition)
removeCustomEvent(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);
condition
- the condition that must be met.
NullPointerException
- if the condition parameter has been set to
null
.Condition
,
removeCustomEvent(Condition)
void removeCustomEvent(Condition condition)
addCustomEvent(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);
condition
- the condition that was previous added and that must be
removed now.
NullPointerException
- if the condition parameter has been set to
null
.Condition
,
addCustomEvent(Condition)
void clearAllEvents()
getAllEvents()
List<Event> getAllEvents()
for (Event event : getAllEvents()) { if (event instanceof HitRobotEvent) { // do something with the event } else if (event instanceof HitByBulletEvent) { // do something with the event } }
Event
,
clearAllEvents()
,
getStatusEvents()
,
getScannedRobotEvents()
,
getBulletHitEvents()
,
getBulletMissedEvents()
,
getBulletHitBulletEvents()
,
getRobotDeathEvents()
List<StatusEvent> getStatusEvents()
for (StatusEvent event : getStatusEvents()) { // do something with the event }
onStatus(StatusEvent)
,
StatusEvent
,
getAllEvents()
List<BulletMissedEvent> getBulletMissedEvents()
for (BulletMissedEvent event : getBulletMissedEvents()) { // do something with the event }
onBulletMissed(BulletMissedEvent)
,
BulletMissedEvent
,
getAllEvents()
List<BulletHitBulletEvent> getBulletHitBulletEvents()
for (BulletHitBulletEvent event : getBulletHitBulletEvents()) { // do something with the event }
onBulletHitBullet(BulletHitBulletEvent)
,
BulletHitBulletEvent
,
getAllEvents()
List<BulletHitEvent> getBulletHitEvents()
for (BulletHitEvent event: getBulletHitEvents()) { // do something with the event }
onBulletHit(BulletHitEvent)
,
BulletHitEvent
,
getAllEvents()
List<HitByBulletEvent> getHitByBulletEvents()
for (HitByBulletEvent event : getHitByBulletEvents()) { // do something with the event }
onHitByBullet(HitByBulletEvent)
,
HitByBulletEvent
,
getAllEvents()
List<HitRobotEvent> getHitRobotEvents()
for (HitRobotEvent event : getHitRobotEvents()) { // do something with the event }
onHitRobot(HitRobotEvent)
,
HitRobotEvent
,
getAllEvents()
List<HitWallEvent> getHitWallEvents()
for (HitWallEvent event : getHitWallEvents()) { // do something with the event }
onHitWall(HitWallEvent)
,
HitWallEvent
,
getAllEvents()
List<RobotDeathEvent> getRobotDeathEvents()
for (RobotDeathEvent event : getRobotDeathEvents()) { // do something with the event }
onRobotDeath(RobotDeathEvent)
,
RobotDeathEvent
,
getAllEvents()
List<ScannedRobotEvent> getScannedRobotEvents()
for (ScannedRobotEvent event : getScannedRobotEvents()) { // do something with the event }
onScannedRobot(ScannedRobotEvent)
,
ScannedRobotEvent
,
getAllEvents()
File getDataDirectory()
RobocodeFileOutputStream
or
RobocodeFileWriter
.
The system will automatically create the directory for you, so you do not
need to create it by yourself.
getDataFile(String)
,
RobocodeFileOutputStream
,
RobocodeFileWriter
File getDataFile(String filename)
RobocodeFileOutputStream
or RobocodeFileWriter
.
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 the sample.SittingDuck
to see an example of how to use this
method.
filename
- the file name of the data file for your robot
getDataDirectory()
,
RobocodeFileOutputStream
,
RobocodeFileWriter
long getDataQuotaAvailable()
getDataDirectory()
,
getDataFile(String)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |