|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectrobocode._Robot
robocode.Robot
robocode._AdvancedRobot
robocode._AdvancedRadiansRobot
robocode.AdvancedRobot
A more advanced type of robot that allows non-blocking calls, custom events, and writes to the filesystem.
If you have not already, you should create a Robot
first.
Robot
Field Summary |
Fields inherited from class robocode.Robot |
out |
Constructor Summary | |
AdvancedRobot()
|
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 immediately. |
void |
execute()
Executes any pending actions, or continues executing actions that are in process. |
java.util.Vector |
getAllEvents()
Returns a vector containing all events currently in the robot's queue. |
java.util.Vector |
getBulletHitBulletEvents()
Returns a vector containing all BulletHitBulletEvents currently in the robot's queue. |
java.util.Vector |
getBulletHitEvents()
Returns a vector containing all BulletHitEvents currently in the robot's queue. |
java.util.Vector |
getBulletMissedEvents()
Returns a vector containing all BulletMissedEvents currently in the robot's queue. |
java.io.File |
getDataDirectory()
Returns a file representing a directory you can write to using RobocodeOutputStream. |
java.io.File |
getDataFile(java.lang.String filename)
Returns a file in your data directory that you can write to RobocodeOutputStream. |
long |
getDataQuotaAvailable()
Returns the quota available in your data directory, in bytes. |
double |
getDistanceRemaining()
Gets distance left in the robot's current move. |
int |
getEventPriority(java.lang.String eventClass)
Returns the current priority of a class of events. |
double |
getGunTurnRemaining()
Gets angle remaining in the gun's turn, in degrees |
java.util.Vector |
getHitByBulletEvents()
Returns a vector containing all HitByBulletEvents currently in the robot's queue. |
java.util.Vector |
getHitRobotEvents()
Returns a vector containing all HitRobotEvents currently in the robot's queue. |
java.util.Vector |
getHitWallEvents()
Returns a vector containing all HitWallEvents currently in the robot's queue. |
double |
getRadarTurnRemaining()
Gets angle remaining in the radar's turn, in degrees. |
java.util.Vector |
getRobotDeathEvents()
Returns a vector containing all RobotDeathEvents currently in the robot's queue. |
java.util.Vector |
getScannedRobotEvents()
Returns a vector containing all ScannedRobotEvents currently in the robot's queue. |
double |
getTurnRemaining()
Gets angle remaining in the robot's turn, in degrees. |
boolean |
isAdjustGunForRobotTurn()
Checks if the gun is set to adjust for the robot turning. |
boolean |
isAdjustRadarForGunTurn()
Checks if the radar is set to adjust for the gun turning. |
boolean |
isAdjustRadarForRobotTurn()
Checks if the radar is set to adjust for the robot turning. |
void |
onCustomEvent(CustomEvent event)
This method will be called when a custom condition is met See the sample robots for examples of use. |
void |
onDeath(DeathEvent event)
This method will be called if your robot dies You should override it in your robot if you want to be informed of this event. |
void |
onSkippedTurn(SkippedTurnEvent event)
This method will be called if you are taking an extremely long time between actions. |
void |
removeCustomEvent(Condition condition)
Removes a custom event (specified by condition). |
void |
setAhead(double distance)
Sets the robot to move ahead by distance This call returns immediately, and will not execute until you call execute() or take an action that executes. |
void |
setBack(double distance)
Sets the robot to move back by distance. |
void |
setEventPriority(java.lang.String eventClass,
int priority)
Set the priority of a class of events. |
void |
setFire(double power)
Sets the gun to fire a bullet. |
Bullet |
setFireBullet(double power)
Fires a bullet. |
void |
setInterruptible(boolean interruptible)
Call this during an event handler to allow new events of the same priority, generated following this call, to restart the event handler. |
void |
setMaxTurnRate(double newMaxTurnRate)
If you would like to turn slower than 10 degrees / tick, call this method to set it. |
void |
setMaxVelocity(double newMaxVelocity)
If you would like to limit your robot's speed to less than 8, call this method. |
void |
setResume()
Sets the robot to resume the movement you stopped in stop() or setStop(), if any. |
void |
setStop()
This call is identical to stop() ,
but returns immediately, and will not execute until you call execute() or take an action that executes.
|
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 |
setTurnGunLeft(double degrees)
Sets the gun to turn left by degrees This call returns immediately, and will not execute until you call execute() or take an action that executes. |
void |
setTurnGunRight(double degrees)
Sets the gun to turn right by degrees. |
void |
setTurnLeft(double degrees)
Sets the robot to turn left by degrees. |
void |
setTurnRadarLeft(double degrees)
Sets the radar to turn left by degrees. |
void |
setTurnRadarRight(double degrees)
Sets the radar to turn right by degrees. |
void |
setTurnRight(double degrees)
Sets the robot to turn right by degrees. |
void |
waitFor(Condition condition)
Does not return until condition.test() returns true. |
Methods inherited from class robocode.Robot |
ahead, back, doNothing, finalize, fire, fireBullet, getBattleFieldHeight, getBattleFieldWidth, getEnergy, getGunCoolingRate, getGunHeading, getGunHeat, getHeading, getHeight, getName, getNumRounds, getOthers, getRadarHeading, getRoundNum, getTime, getVelocity, getWidth, getX, getY, onBulletHit, onBulletHitBullet, onBulletMissed, onHitByBullet, onHitRobot, onHitWall, onPaint, onRobotDeath, onScannedRobot, onWin, resume, run, scan, setAdjustGunForRobotTurn, setAdjustRadarForGunTurn, setAdjustRadarForRobotTurn, setColors, stop, stop, turnGunLeft, turnGunRight, turnLeft, turnRadarLeft, turnRadarRight, turnRight |
Methods inherited from class robocode._Robot |
getBattleNum, getGunCharge, getGunImageName, getLife, getNumBattles, getRadarImageName, getRobotImageName, setGunImageName, setPeer, setRadarImageName, setRobotImageName, uninitializedException |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public AdvancedRobot()
Method Detail |
public double getDistanceRemaining()
public void setAhead(double distance)
public void setBack(double distance)
public void setTurnLeft(double degrees)
public void setTurnRight(double degrees)
public void setFire(double power)
power
- The energy given to the bullet, and subtracted from your energy.Robot.fire(double)
,
Robot.fireBullet(double)
,
setFireBullet(double)
,
Robot.fireBullet(double)
public Bullet setFireBullet(double power)
Robot.fire(double)
,
Robot.fireBullet(double)
,
setFire(double)
public void addCustomEvent(Condition condition)
condition
- The condition that must be met.public void clearAllEvents()
public void execute()
In this example the robot will move while turning
setTurnRight(90); setAhead(100); execute(); while (getDistanceRemaining() != 0 && getTurnRemaining() != 0) { execute(); }
public java.util.Vector getAllEvents()
Example:
Vector v = getAllEvents(); Event e; for (int i = 0; i < v.size(); i++) { e = (Event)v.elementAt(i); if (e instanceof HitRobotEvent) (do something with e) else if (e instanceof HitByBulletEvent) (so something else with e) }
Robot.onBulletHit(robocode.BulletHitEvent)
,
Robot.onBulletHitBullet(robocode.BulletHitBulletEvent)
,
Robot.onBulletMissed(robocode.BulletMissedEvent)
,
Robot.onHitByBullet(robocode.HitByBulletEvent)
,
Robot.onHitRobot(robocode.HitRobotEvent)
,
Robot.onHitWall(robocode.HitWallEvent)
,
onSkippedTurn(robocode.SkippedTurnEvent)
,
BulletHitEvent
,
BulletMissedEvent
,
HitByBulletEvent
,
HitRobotEvent
,
HitWallEvent
,
SkippedTurnEvent
,
Event
,
Vector
public java.util.Vector getBulletHitBulletEvents()
Example:
Vector v = getBulletHitBulletEvents(); BulletHitBulletEvent e; for (int i = 0; i < e.size(); i++) { e = (BulletHitBulletEvent)v.elementAt(i); (do something with e) }
Robot.onBulletHitBullet(robocode.BulletHitBulletEvent)
,
BulletHitBulletEvent
,
Vector
public java.util.Vector getBulletHitEvents()
Example:
Vector v = getBulletHitEvents(); BulletHitEvent e; for (int i = 0; i < e.size(); i++) { e = (BulletHitEvent)v.elementAt(i); (do something with e) }
Robot.onBulletHit(robocode.BulletHitEvent)
,
BulletHitEvent
,
Vector
public java.util.Vector getBulletMissedEvents()
Example:
Vector v = getBulletHitEvents(); BulletMissedEvent e; for (int i = 0; i < e.size(); i++) { e = (BulletMissedEvent)v.elementAt(i); (do something with e) }
Robot.onBulletMissed(robocode.BulletMissedEvent)
,
BulletMissedEvent
,
Vector
public java.io.File getDataDirectory()
getDataFile(java.lang.String)
public java.io.File getDataFile(java.lang.String filename)
getDataDirectory()
public long getDataQuotaAvailable()
getDataDirectory()
public int getEventPriority(java.lang.String eventClass)
int myHitRobotPriority = getEventPriority("HitRobotEvent");
eventClass
- The name of the event class (string)setEventPriority(java.lang.String, int)
public double getGunTurnRemaining()
public java.util.Vector getHitByBulletEvents()
Example:
Vector v = getHitByBulletEvents(); HitByBulletEvent e; for (int i = 0; i < e.size(); i++) { e = (HitByBulletEvent)v.elementAt(i); (do something with e) }
Robot.onHitByBullet(robocode.HitByBulletEvent)
,
HitByBulletEvent
,
Vector
public java.util.Vector getHitRobotEvents()
Example:
Vector v = getHitRobotEvents(); HitRobotEvent e; for (int i = 0; i < e.size(); i++) { e = (HitRobotEvent)v.elementAt(i); (do something with e) }
Robot.onHitRobot(robocode.HitRobotEvent)
,
HitRobotEvent
,
Vector
public java.util.Vector getHitWallEvents()
Example:
Vector v = getHitWallEvents(); HitWallEvent e; for (int i = 0; i < e.size(); i++) { e = (HitWallEvent)v.elementAt(i); (do something with e) }
Robot.onHitWall(robocode.HitWallEvent)
,
HitWallEvent
,
Vector
public double getRadarTurnRemaining()
public java.util.Vector getRobotDeathEvents()
Example:
Vector v = getRobotDeathEvents(); RobotDeathEvent e; for (int i = 0; i < e.size(); i++) { e = (RobotDeathEvent)v.elementAt(i); (do something with e) }
Robot.onRobotDeath(robocode.RobotDeathEvent)
,
RobotDeathEvent
,
Vector
public java.util.Vector getScannedRobotEvents()
Example:
Vector v = getScannedRobotEvents(); ScannedRobotEvent e; for (int i = 0; i < e.size(); i++) { e = (ScannedRobotEvent)v.elementAt(i); (do something with e) }
Robot.onScannedRobot(robocode.ScannedRobotEvent)
,
ScannedRobotEvent
,
Vector
public double getTurnRemaining()
public boolean isAdjustGunForRobotTurn()
Robot.setAdjustGunForRobotTurn(boolean)
public boolean isAdjustRadarForGunTurn()
Robot.setAdjustRadarForGunTurn(boolean)
public void onCustomEvent(CustomEvent event)
event
- The event set by the gameaddCustomEvent(robocode.Condition)
,
CustomEvent
,
Event
public void removeCustomEvent(Condition condition)
condition
- The condition to removeaddCustomEvent(robocode.Condition)
public void setEventPriority(java.lang.String eventClass, int priority)
setEventPriority("RobotDeathEvent",15);The default priorities are, from lowest to highest:
ScannedRobotEvent: 10 HitRobotEvent: 20 HitWallEvent: 30 HitByBulletEvent: 40 BulletHitEvent: 50 BulletHitBulletEvent: 50 BulletMissedEvent: 60 RobotDeathEvent: 70 CustomEvent: 80 SkippedTurnEvent: 100 WinEvent: 100 DeathEvent: 100
eventClass
- String containing name of the event class you wish to set priority forpriority
- the new priority for that class_Robot.setInterruptible(boolean)
public void setInterruptible(boolean interruptible)
Example
onScannedRobot(ScannedRobotEvent e) { fire(1); setInterruptible(true); ahead(100); // If you see a robot while moving ahead, // this handler will start from the top // Without setInterruptible, we wouldn't // receive scan events at all! // We'll only get here if we don't see a robot during the move. out.println("Ok, I can't see anyone"); }
setInterruptible
in class _Robot
interruptible
- Whether this event handler should be interrupted on new events of same priority.public void setMaxTurnRate(double newMaxTurnRate)
public void setMaxVelocity(double newMaxVelocity)
public void setResume()
setStop()
,
Robot.stop()
public void setStop()
stop()
,
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, this will have no effect.
This call is equivalent to calling setStop(false);
setStop(boolean)
,
setResume()
,
Robot.stop()
,
Robot.resume()
public 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).
setStop()
,
setResume()
,
Robot.stop()
,
Robot.resume()
public void setTurnGunLeft(double degrees)
public void setTurnGunRight(double degrees)
public void setTurnRadarLeft(double degrees)
public void setTurnRadarRight(double degrees)
public void waitFor(Condition condition)
public boolean isAdjustRadarForRobotTurn()
Robot.setAdjustRadarForRobotTurn(boolean)
public void onDeath(DeathEvent event)
onDeath
in class Robot
event
- The event set by the gameDeathEvent
,
Event
public void onSkippedTurn(SkippedTurnEvent event)
event
- The event set by the gameSkippedTurnEvent
,
Event
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |