robocode
Class Ship

java.lang.Object
  extended by robocode._RobotBase
      extended by robocode.Ship
All Implemented Interfaces:
Runnable, IBackCannonFunctions, IFrontCannonFunctions, IRadarFunctions, IAdvancedEvents, IAdvancedRobot, IBasicEvents, IBasicEvents2, IBasicEvents3, IBasicEvents4, IBasicRobot, IPaintEvents, IPaintRobot, IShip

public class Ship
extends _RobotBase
implements IShip, IBasicEvents4, IPaintEvents, IPaintRobot, IAdvancedRobot, IAdvancedEvents

This is the improved version of the Ship which acts far more like a ship.

Since:
1.8.3.0 Alpha 1
Version:
0.3
Author:
Thales B.V. / Jiri Waning / Thomas Hakkers

Field Summary
 
Fields inherited from class robocode._RobotBase
out
 
Constructor Summary
Ship()
           
 
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.
 void execute()
          Executes any pending actions, or continues executing actions that are in process.
 void fireBackCannon(double power)
          Fires the a bullet/missile from the back cannon with the given power
 void fireFrontCannon(double power)
          Fires the a bullet/missile from the front cannon with the given power
 IAdvancedEvents getAdvancedEventListener()
          Do not call this method!
 Vector<Event> getAllEvents()
          Returns a vector containing all events currently in the robot's queue.
 boolean getBackCannonAtBlindSpot()
          Returns true when the blindSpot has been reached for the backCannon
 double getBackCannonHeadingDegrees()
          Retrieve the angle the back cannon is heading in degrees.
 double getBackCannonHeadingRadians()
          Retrieve the angle the back cannon is heading in radians.
 double getBackCannonTurnRemainingDegrees()
          Returns the amount the Back Cannon still has to turn in degrees.
 double getBackCannonTurnRemainingRadians()
          Returns the amount the Back Cannon still has to turn in radians.
 IBasicEvents getBasicEventListener()
          This method is called by the game to notify this robot about basic robot event.
 double getBattleFieldHeight()
          Returns the height of the current battlefield measured in pixels.
 double getBattleFieldWidth()
          Returns the width of the current battlefield measured in pixels.
 double getBodyHeadingDegrees()
          Returns the heading of the Ship in Degrees.
 double getBodyHeadingRadians()
          Returns the heading of the Ship in Radians.
 double getBodyTurnRemainingDegrees()
          Deprecated to avoid confusion Returns the angle remaining in the robots's turn, in degrees.
 double getBodyTurnRemainingRadians()
          Returns the angle remaining in the robot's turn, in radians.
 Vector<BulletHitBulletEvent> getBulletHitBulletEvents()
          Returns a vector containing all BulletHitBulletEvents currently in the robot's queue.
 Vector<BulletHitEvent> getBulletHitEvents()
          Returns a vector containing all BulletHitEvents currently in the robot's queue.
 Vector<BulletMissedEvent> getBulletMissedEvents()
          Returns a vector containing all BulletMissedEvents currently in the robot's queue.
 double getComponentHeadingDegrees(int index)
          Returns the absolute heading of the component in degrees.
 double getComponentHeadingRadians(int index)
          Returns the absolute heading of the component in radians.
 BlindSpot getCopyOfBlindSpotBackCannon()
          Returns a copy of the BlindSpot that the back cannon has.
 BlindSpot getCopyOfBlindSpotFrontCannon()
          Returns a copy of the BlindSpot that the back cannon has.
 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.
 double getDistanceRemaining()
          Returns the distance remaining in the robot's current move measured in pixels.
 double getEnergy()
          Returns the robot's current energy.
 int getEventPriority(String eventClass)
          Returns the current priority of a class of events.
 double getFirePower(int index)
          Returns the FirePower of the specified component.
 boolean getFrontCannonAtBlindSpot()
          Returns true when the blindSpot has been reached for the backCannon
 double getFrontCannonHeadingDegrees()
          Retrieve the angle the front cannon is heading in degrees.
 double getFrontCannonHeadingRadians()
          Retrieve the angle the front cannon is heading in radians.
 double getFrontCannonTurnRemainingDegrees()
          Returns the amount the Front Cannon still has to turn in degrees.
 double getFrontCannonTurnRemainingRadians()
          Returns the amount the Front Cannon still has to turn in radians.
 double getGunHeatComponent(int index)
          Returns the gunHeat of the given component.
 Vector<HitByBulletEvent> getHitByBulletEvents()
          Returns a vector containing all HitByBulletEvents currently in the robot's queue.
 Vector<HitRobotEvent> getHitRobotEvents()
          Returns a vector containing all HitRobotEvents currently in the robot's queue.
 Vector<HitWallEvent> getHitWallEvents()
          Returns a vector containing all HitWallEvents currently in the robot's queue.
 int getOthers()
          Returns how many opponents that are left in the current round.
 IPaintEvents getPaintEventListener()
          This method is called by the game to notify this robot about painting events.
 double getRadarHeadingDegrees()
          Retrieve the angle the radar is heading in degrees.
 double getRadarHeadingRadians()
          Retrieve the angle the radar is heading in radians.
 double getRadarTurnRemainingDegrees()
          Returns the amount the Radar still has to turn in degrees.
 double getRadarTurnRemainingRadians()
          Returns the amount the Radar still has to turn in radians.
 Vector<RobotDeathEvent> getRobotDeathEvents()
          Returns a vector containing all RobotDeathEvents currently in the robot's queue.
 Runnable getRobotRunnable()
          This method is called by the game to invoke the run() method of your robot, where the program of your robot is implemented.
 Vector<ScannedRobotEvent> getScannedRobotEvents()
          Returns a vector containing all ScannedRobotEvents currently in the robot's queue.
 Vector<StatusEvent> getStatusEvents()
          Returns a vector containing all StatusEvents currently in the robot's queue.
 long getTime()
          Returns the game time of the current round, where the time is equal to the current turn in the round.
 double getVelocity()
          Returns the velocity the Ship is going at in knots (pixels per second)
 double getX()
          Returns the X position of the robot. (0,0) is at the bottom left of the battlefield.
 double getXBackCannon()
          Returns the current X-coordinate of your back cannon
 double getXFrontCannon()
          Returns the current X-coordinate of your front cannon
 double getXMiddle()
          Returns the X coordinate of the middle of the Ship.
 double getXRadar()
          Returns the current X-coordinate of the Radar
 double getY()
          Returns the Y position of the robot. (0,0) is at the bottom left of the battlefield.
 double getYBackCannon()
          Returns the current Y-coordinate of your back cannon
 double getYFrontCannon()
          Returns the current Y-coordinate of your front cannon
 double getYMiddle()
          Returns the Y coordinate of the middle of the Ship.
 double getYRadar()
          Returns the current Y-coordinate of the Radar
 void onBattleEnded(BattleEndedEvent event)
          This method is called after the end of the battle, even when the battle is aborted.
 void onBulletHit(BulletHitEvent event)
          This method is called when one of your bullets hits another robot.
 void onBulletHitBullet(BulletHitBulletEvent event)
          This method is called when one of your bullets hits another bullet.
 void onBulletMissed(BulletMissedEvent event)
          This method is called when one of your bullets misses, i.e. hits a wall.
 void onCustomEvent(CustomEvent event)
          This method is called when a custom condition is met.
 void onDeath(DeathEvent event)
          This method is called if your robot dies.
 void onHitByBullet(HitByBulletEvent event)
          This method is called when your robot is hit by a bullet.
 void onHitByMine(HitByMineEvent event)
          Triggers when your Ship get hit by a Mine.
 void onHitRobot(HitRobotEvent event)
          This method is called when your robot collides with another robot.
 void onHitWall(HitWallEvent event)
          This method is called when your robot collides with a wall.
 void onMineHit(MineHitEvent event)
          Triggers when your Mine has hit a Ship (Can be your own Ship)
 void onMineHitMine(MineHitMineEvent event)
          Triggers when your Mine has hit another Mine.
 void onPaint(Graphics2D g)
          This method is called every time the robot is painted.
 void onRobotDeath(RobotDeathEvent event)
          This method is called when another robot dies.
 void onRoundEnded(RoundEndedEvent event)
          This method is called after the end of a round.
 void onScannedRobot(ScannedRobotEvent event)
          Deprecated. Use onScannedShip(ScannedShipEvent event) instead.
 void onScannedShip(ScannedShipEvent event)
          This method is called when your robot sees another robot, i.e. when the robot's radar scan "hits" another robot.
 void onSkippedTurn(SkippedTurnEvent event)
          This method is called if the robot is using too much time between actions.
 void onStatus(StatusEvent event)
          This method is called every turn in a battle round in order to provide the robot status as a complete snapshot of the robot's current state at that specific time.
 void onWin(WinEvent event)
          This method is called if your robot wins a battle.
 Mine placeMine(double power)
           
 void removeCustomEvent(Condition condition)
          Removes a custom event that was previously added by calling addCustomEvent(Condition).
 void resume()
          Immediately resumes the movement you stopped by stop(), if any.
 void run()
          This is the method you have to override to create your own ship.
 void scan()
           
 void setAdjustComponentForShipTurn(int index, boolean independent)
          Sets whether the component moves dependently from the Ship or not.
 void setAhead(double distance)
          Immediately moves your robot ahead (forward) by distance measured in pixels.
 void setBack(double distance)
          Moves your Ship back by the given number of pixels.
 void setBackCannonColor(Color color)
          Sets the color of the back cannon.
 void setBodyColor(Color color)
          Sets the color of the body of the ship
 void setBulletColor(Color color)
          Sets the BulletColor for both Front and Back Cannon.
 void setBulletColorBack(Color color)
          Sets the Bullet Color for the Back Cannon
 void setBulletColorFront(Color color)
          Sets the Bullet Color for the Front Cannon
 void setCourseDegrees(double angle)
          Sets the course towards the specified heading.
 void setCourseRadians(double angle)
          Sets the course towards the specified heading.
 void setEventPriority(String eventClass, int priority)
          Sets the priority of a class of events.
 void setFrontCannonColor(Color color)
          Sets the color of the front cannon.
 void setInterruptible(boolean interruptible)
          Call this during an event handler to allow new events of the same priority to restart the event handler.
 void setMaxKnots(double maxKnots)
          Sets the maximum amount of knots you want to travel per turn.
 void setMineComponentColor(Color color)
           
 void setRadarColor(Color color)
          Sets the color of the radar.
 void setResume()
          Sets the robot to resume the movement stopped by stop() or setStop(), if any.
 void setScanColor(Color color)
          Sets the Color of your scan
 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 setTurnBackCannonLeftDegrees(double angle)
          Turns the back cannon towards the left by the amount given in degrees.
 void setTurnBackCannonLeftRadians(double angle)
          Turns the back cannon towards the left by the amount given in radians.
 void setTurnBackCannonRightDegrees(double angle)
          Turns the back cannon towards the right by the amount given in degrees.
 void setTurnBackCannonRightRadians(double angle)
          Turns the back cannon towards the right by the amount given in radians.
 void setTurnFrontCannonLeftDegrees(double angle)
          Turns the front cannon towards the left by the amount given in degrees.
 void setTurnFrontCannonLeftRadians(double angle)
          Turns the front cannon towards the left by the amount given in radians.
 void setTurnFrontCannonRightDegrees(double angle)
          Turns the front cannon towards the right by the amount given in degrees.
 void setTurnFrontCannonRightRadians(double angle)
          Turns the front cannon towards the right by the amount given in radians.
 void setTurnLeftDegrees(double angle)
          Attempts to turn your Ship by the given angle in degrees towards the left.
 void setTurnLeftRadians(double radians)
          Attempts to turn your Ship by the given angle in radians towards the left.
 void setTurnRadarLeftDegrees(double angle)
          Set the angle the Radar needs to turn towards the left in degrees.
 void setTurnRadarLeftRadians(double angle)
          Set the angle the Radar needs to turn towards the Left in radians.
 void setTurnRadarRightDegrees(double angle)
          Set the angle the Radar needs to turn towards the right in degrees.
 void setTurnRadarRightRadians(double angle)
          Set the angle the Radar needs to turn towards the Left in radians.
 void setTurnRightDegrees(double angle)
          Attempts to turn your Ship by the given angle in degrees towards the right.
 void setTurnRightRadians(double radians)
          Attempts to turn your Ship by the given angle in radians towards the right.
 void stop()
          Immediately stops all movement, and saves it for a call to resume().
 void stop(boolean overwrite)
          Immediately stops all movement, and saves it for a call to resume().
 void waitFor(Condition condition)
          Does not return until a condition is met, i.e. when a Condition.test() returns true.
 
Methods inherited from class robocode._RobotBase
finalize, setOut, setPeer
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface robocode.robotinterfaces.IBasicRobot
setOut, setPeer
 

Constructor Detail

Ship

public Ship()
Method Detail

setTurnRadarLeftDegrees

public void setTurnRadarLeftDegrees(double angle)
Set the angle the Radar needs to turn towards the left in degrees. If the current angle is 50, and you call this function like setTurnRadarLeftDegrees(40), the angle will end up being 10. (Not instantaneously, of course)

Specified by:
setTurnRadarLeftDegrees in interface IRadarFunctions
Parameters:
angle - The angle you want to turn the radar towards the left in degrees.

setTurnRadarRightDegrees

public void setTurnRadarRightDegrees(double angle)
Set the angle the Radar needs to turn towards the right in degrees. If the current angle is 50, and you call this function like setTurnRadarRightDegrees(40), the angle will end up being 90. (Not instantaneously, of course)

Specified by:
setTurnRadarRightDegrees in interface IRadarFunctions
Parameters:
angle - The angle you want to turn the radar towards the right in degrees.

setTurnRadarLeftRadians

public void setTurnRadarLeftRadians(double angle)
Set the angle the Radar needs to turn towards the Left in radians. If the current angle is PI, and you call this function like setTurnRadarLeftRadians(PI/2), the angle will end up being PI/2. (Not instantaneously, of course)

Specified by:
setTurnRadarLeftRadians in interface IRadarFunctions
Parameters:
angle - The angle you want to turn the radar towards the left in radians.

setTurnRadarRightRadians

public void setTurnRadarRightRadians(double angle)
Set the angle the Radar needs to turn towards the Left in radians. If the current angle is PI, and you call this function like setTurnRadarRightRadians(PI/2), the angle will end up being 3PI/2. (Not instantaneously, of course)

Specified by:
setTurnRadarRightRadians in interface IRadarFunctions
Parameters:
angle - The angle you want to turn the radar towards the right in radians.

getRadarHeadingRadians

public double getRadarHeadingRadians()
Retrieve the angle the radar is heading in radians.

Specified by:
getRadarHeadingRadians in interface IRadarFunctions
Returns:
The heading of the radar in radians, this is not relative to the ship.

getRadarHeadingDegrees

public double getRadarHeadingDegrees()
Retrieve the angle the radar is heading in degrees.

Specified by:
getRadarHeadingDegrees in interface IRadarFunctions
Returns:
The heading of the radar in degrees, this is not relative to the ship.

getRadarTurnRemainingRadians

public double getRadarTurnRemainingRadians()
Returns the amount the Radar still has to turn in radians.

Specified by:
getRadarTurnRemainingRadians in interface IRadarFunctions
Returns:
turnRemaining for Radar in radians.

getRadarTurnRemainingDegrees

public double getRadarTurnRemainingDegrees()
Returns the amount the Radar still has to turn in degrees.

Specified by:
getRadarTurnRemainingDegrees in interface IRadarFunctions
Returns:
turnRemaining for Front Cannon in degrees.

setTurnFrontCannonLeftDegrees

public void setTurnFrontCannonLeftDegrees(double angle)
Turns the front cannon towards the left by the amount given in degrees. The cannon will be stopped when it reaches its blindspot. TurnRemaining won't go to 0 when this happens.

Specified by:
setTurnFrontCannonLeftDegrees in interface IFrontCannonFunctions
Parameters:
angle - The angle in degrees you want to rotate your front cannon to the left.

setTurnFrontCannonRightDegrees

public void setTurnFrontCannonRightDegrees(double angle)
Turns the front cannon towards the right by the amount given in degrees. The cannon will be stopped when it reaches its blindspot. TurnRemaining won't go to 0 when this happens.

Specified by:
setTurnFrontCannonRightDegrees in interface IFrontCannonFunctions
Parameters:
angle - The angle in degrees you want to rotate your front cannon to the right.

setTurnFrontCannonLeftRadians

public void setTurnFrontCannonLeftRadians(double angle)
Turns the front cannon towards the left by the amount given in radians. The cannon will be stopped when it reaches its blindspot. TurnRemaining won't go to 0 when this happens.

Specified by:
setTurnFrontCannonLeftRadians in interface IFrontCannonFunctions
Parameters:
angle - The angle in radians you want to rotate your front cannon to the left.

setTurnFrontCannonRightRadians

public void setTurnFrontCannonRightRadians(double angle)
Turns the front cannon towards the right by the amount given in radians. The cannon will be stopped when it reaches its blindspot. TurnRemaining won't go to 0 when this happens.

Specified by:
setTurnFrontCannonRightRadians in interface IFrontCannonFunctions
Parameters:
angle - The angle in radians you want to rotate your front cannon to the right.

getFrontCannonHeadingRadians

public double getFrontCannonHeadingRadians()
Retrieve the angle the front cannon is heading in radians.

Specified by:
getFrontCannonHeadingRadians in interface IFrontCannonFunctions
Returns:
The heading of the front cannon in radians, this is not relative to the ship.

getFrontCannonHeadingDegrees

public double getFrontCannonHeadingDegrees()
Retrieve the angle the front cannon is heading in degrees.

Specified by:
getFrontCannonHeadingDegrees in interface IFrontCannonFunctions
Returns:
The heading of the front cannon in degrees, this is not relative to the ship.

getCopyOfBlindSpotFrontCannon

public BlindSpot getCopyOfBlindSpotFrontCannon()
Returns a copy of the BlindSpot that the back cannon has. The BlindSpot offers great utilities that will help you out working with a BlindSpot.

Specified by:
getCopyOfBlindSpotFrontCannon in interface IFrontCannonFunctions
Returns:
The BlindSpot of the back cannon.
See Also:
Furthest you can move to the left, Furthest you can move to the right, Returns whether the destination is within the BlindSpot

getFrontCannonAtBlindSpot

public boolean getFrontCannonAtBlindSpot()
Returns true when the blindSpot has been reached for the backCannon

Specified by:
getFrontCannonAtBlindSpot in interface IFrontCannonFunctions
Returns:

getFrontCannonTurnRemainingRadians

public double getFrontCannonTurnRemainingRadians()
Returns the amount the Front Cannon still has to turn in radians. Note: When the blindspot is reached, turn remaining will NOT be 0.

Specified by:
getFrontCannonTurnRemainingRadians in interface IFrontCannonFunctions
Returns:
turnRemaining for Front Cannon in radians.

getFrontCannonTurnRemainingDegrees

public double getFrontCannonTurnRemainingDegrees()
Returns the amount the Front Cannon still has to turn in degrees. Note: When the blindspot is reached, turn remaining will NOT be 0.

Specified by:
getFrontCannonTurnRemainingDegrees in interface IFrontCannonFunctions
Returns:
turnRemaining for Front Cannon in degrees.

setTurnBackCannonLeftDegrees

public void setTurnBackCannonLeftDegrees(double angle)
Turns the back cannon towards the left by the amount given in degrees. The cannon will be stopped when it reaches its blindspot. TurnRemaining won't go to 0 when this happens.

Specified by:
setTurnBackCannonLeftDegrees in interface IBackCannonFunctions
Parameters:
angle - The angle in degrees you want to rotate your back cannon to the left.

setTurnBackCannonRightDegrees

public void setTurnBackCannonRightDegrees(double angle)
Turns the back cannon towards the right by the amount given in degrees. The cannon will be stopped when it reaches its blindspot. TurnRemaining won't go to 0 when this happens.

Specified by:
setTurnBackCannonRightDegrees in interface IBackCannonFunctions
Parameters:
angle - The angle in degrees you want to rotate your back cannon to the right.

setTurnBackCannonLeftRadians

public void setTurnBackCannonLeftRadians(double angle)
Turns the back cannon towards the left by the amount given in radians. The cannon will be stopped when it reaches its blindspot. TurnRemaining won't go to 0 when this happens.

Specified by:
setTurnBackCannonLeftRadians in interface IBackCannonFunctions
Parameters:
angle - The angle in radians you want to rotate your back cannon to the left.

setTurnBackCannonRightRadians

public void setTurnBackCannonRightRadians(double angle)
Turns the back cannon towards the right by the amount given in radians. The cannon will be stopped when it reaches its blindspot. TurnRemaining won't go to 0 when this happens.

Specified by:
setTurnBackCannonRightRadians in interface IBackCannonFunctions
Parameters:
angle - The angle in radians you want to rotate your back cannon to the right.

getBackCannonHeadingRadians

public double getBackCannonHeadingRadians()
Retrieve the angle the back cannon is heading in radians.

Specified by:
getBackCannonHeadingRadians in interface IBackCannonFunctions
Returns:
The heading of the back cannon in radians, this is not relative to the ship.

getBackCannonHeadingDegrees

public double getBackCannonHeadingDegrees()
Retrieve the angle the back cannon is heading in degrees.

Specified by:
getBackCannonHeadingDegrees in interface IBackCannonFunctions
Returns:
The heading of the back cannon in degrees, this is not relative to the ship.

getCopyOfBlindSpotBackCannon

public BlindSpot getCopyOfBlindSpotBackCannon()
Returns a copy of the BlindSpot that the back cannon has. The BlindSpot offers great utilities that will help you out working with a BlindSpot.

Specified by:
getCopyOfBlindSpotBackCannon in interface IBackCannonFunctions
Returns:
The BlindSpot of the back cannon.
See Also:
Furthest you can move to the left, Furthest you can move to the right, Returns whether the destination is within the BlindSpot

getBackCannonAtBlindSpot

public boolean getBackCannonAtBlindSpot()
Returns true when the blindSpot has been reached for the backCannon

Specified by:
getBackCannonAtBlindSpot in interface IBackCannonFunctions
Returns:

getBackCannonTurnRemainingRadians

public double getBackCannonTurnRemainingRadians()
Returns the amount the Back Cannon still has to turn in radians. Note: When the blindspot is reached, turn remaining will NOT be 0.

Specified by:
getBackCannonTurnRemainingRadians in interface IBackCannonFunctions
Returns:
turnRemaining for Back Cannon in radians.

getBackCannonTurnRemainingDegrees

public double getBackCannonTurnRemainingDegrees()
Returns the amount the Back Cannon still has to turn in degrees. Note: When the blindspot is reached, turn remaining will NOT be 0.

Specified by:
getBackCannonTurnRemainingDegrees in interface IBackCannonFunctions
Returns:
turnRemaining for Back Cannon in degrees.

fireFrontCannon

public void fireFrontCannon(double power)
Fires the a bullet/missile from the front cannon with the given power

Specified by:
fireFrontCannon in interface IFrontCannonFunctions
Parameters:
power - The power you want to shoot your bullet/missile at. The value is a double between 0.1 and 3.0

fireBackCannon

public void fireBackCannon(double power)
Fires the a bullet/missile from the back cannon with the given power

Specified by:
fireBackCannon in interface IBackCannonFunctions
Parameters:
power - The power you want to shoot your bullet/missile at. The value is a double between 0.1 and 3.0

setCourseDegrees

public void setCourseDegrees(double angle)
Sets the course towards the specified heading.

Specified by:
setCourseDegrees in interface IShip
Parameters:
angle - The angle in degrees to which we want to set course. (0 = North, 90 = East, etc)

setBodyColor

public void setBodyColor(Color color)
Sets the color of the body of the ship

Specified by:
setBodyColor in interface IShip
Parameters:
color - The color you wish your ship to be

setFrontCannonColor

public void setFrontCannonColor(Color color)
Sets the color of the front cannon. Use this to make your Ship look pretty. You can either use the preconfigured colors like: Color.MAGENTA or Color.BLUE Or you can make your own custom colors by providing a Color like new Color(20, 50, 80), where the 3 arguments stand for Red Green Blue. (All of them must be integers in between 0 and 255)

Specified by:
setFrontCannonColor in interface IFrontCannonFunctions
Parameters:
color - The color you want your front cannon to be.

setRadarColor

public void setRadarColor(Color color)
Sets the color of the radar. Use this to make your Ship look pretty. You can either use the preconfigured colors like: Color.MAGENTA or Color.BLUE Or you can make your own custom colors by providing a Color like new Color(20, 50, 80), where the 3 arguments stand for Red Green Blue. (All of them must be integers in between 0 and 255)

Specified by:
setRadarColor in interface IRadarFunctions
Parameters:
color - The color you want your radar to be.

setBackCannonColor

public void setBackCannonColor(Color color)
Sets the color of the back cannon. Use this to make your Ship look pretty. You can either use the preconfigured colors like: Color.MAGENTA or Color.BLUE Or you can make your own custom colors by providing a Color like new Color(20, 50, 80), where the 3 arguments stand for Red Green Blue. (All of them must be integers in between 0 and 255)

Specified by:
setBackCannonColor in interface IBackCannonFunctions
Parameters:
color - The color you want your back cannon to be.

setBulletColor

public void setBulletColor(Color color)
Sets the BulletColor for both Front and Back Cannon. In case you're lazy.

Parameters:
color - The Color you want your bullets to be.

setBulletColorBack

public void setBulletColorBack(Color color)
Sets the Bullet Color for the Back Cannon

Specified by:
setBulletColorBack in interface IBackCannonFunctions
Parameters:
color - The Color you want the Bullets the Back Cannon shoots to be.

setBulletColorFront

public void setBulletColorFront(Color color)
Sets the Bullet Color for the Front Cannon

Specified by:
setBulletColorFront in interface IFrontCannonFunctions
Parameters:
color - The Color you want the Bullets the Front Cannon shoots to be.

setScanColor

public void setScanColor(Color color)
Sets the Color of your scan

Specified by:
setScanColor in interface IRadarFunctions
Parameters:
color - The color you want your scan to be.

setTurnLeftRadians

public void setTurnLeftRadians(double radians)
Attempts to turn your Ship by the given angle in radians towards the left. Remember that Ships can't turn when they're not moving.

Specified by:
setTurnLeftRadians in interface IShip
Parameters:
radians - The angle in radians we want to rotate to the left.

setTurnRightRadians

public void setTurnRightRadians(double radians)
Attempts to turn your Ship by the given angle in radians towards the right. Remember that Ships can't turn when they're not moving.

Specified by:
setTurnRightRadians in interface IShip
Parameters:
radians - The angle in radians we want to rotate to the right.

setTurnLeftDegrees

public void setTurnLeftDegrees(double angle)
Attempts to turn your Ship by the given angle in degrees towards the left. Remember that Ships can't turn when they're not moving.

Specified by:
setTurnLeftDegrees in interface IShip
Parameters:
angle - The angle in degrees we want to rotate to the left.

setTurnRightDegrees

public void setTurnRightDegrees(double angle)
Attempts to turn your Ship by the given angle in degrees towards the right. Remember that Ships can't turn when they're not moving.

Specified by:
setTurnRightDegrees in interface IShip
Parameters:
angle - The angle in degrees we want to rotate to the right.

setAdjustComponentForShipTurn

public void setAdjustComponentForShipTurn(int index,
                                          boolean independent)
Sets whether the component moves dependently from the Ship or not. Can only be called if the turnRemaining on the component equals 0. THOMA_NOTE: Might change this in the future to work even if the turn remaining isn't 0.

Specified by:
setAdjustComponentForShipTurn in interface IShip
Parameters:
index - The index of the component
independent - True for independent movement. False of dependent movement.

setMaxKnots

public void setMaxKnots(double maxKnots)
Sets the maximum amount of knots you want to travel per turn.

Specified by:
setMaxKnots in interface IShip

getFirePower

public double getFirePower(int index)
Returns the FirePower of the specified component. Returns 0 if the Component isn't a WeaponComponent.

Parameters:
index -
Returns:

scan

public void scan()
Specified by:
scan in interface IShip

execute

public void execute()
Executes any pending actions, or continues executing actions that are in process. This call returns after the actions have been started.

Note that ships must call this function in order to execute pending set* calls like e.g. IShip.setAhead(double), IShip.setTurnLeftDegrees(double) etc. Otherwise, these calls will never get executed.

Specified by:
execute in interface IShip

onBattleEnded

public void onBattleEnded(BattleEndedEvent event)
This method is called after the end of the battle, even when the battle is aborted. You should override it in your robot if you want to be informed of this event.

Example:

   public void onBattleEnded(BattleEndedEvent event) {
       out.println("The battle has ended");
   }
 

Specified by:
onBattleEnded in interface IBasicEvents2
Parameters:
event - the BattleEndedEvent set by the game
See Also:
BattleEndedEvent, IBasicEvents3.onRoundEnded(RoundEndedEvent), WinEvent, DeathEvent, Event

onBulletHit

public void onBulletHit(BulletHitEvent event)
This method is called when one of your bullets hits another robot. You should override it in your robot if you want to be informed of this event.

Example:

   public void onBulletHit(BulletHitEvent event) {
       out.println("I hit " + event.getName() + "!");
   }
 

Specified by:
onBulletHit in interface IBasicEvents
Parameters:
event - the bullet-hit event set by the game
See Also:
BulletHitEvent, Event

onBulletHitBullet

public void onBulletHitBullet(BulletHitBulletEvent event)
This method is called when one of your bullets hits another bullet. You should override it in your robot if you want to be informed of this event.

Example:

   public void onBulletHitBullet(BulletHitBulletEvent event) {
       out.println("I hit a bullet fired by " + event.getBullet().getName() + "!");
   }
 

Specified by:
onBulletHitBullet in interface IBasicEvents
Parameters:
event - the bullet-hit-bullet event set by the game
See Also:
BulletHitBulletEvent, Event

onBulletMissed

public void onBulletMissed(BulletMissedEvent event)
This method is called when one of your bullets misses, i.e. hits a wall. You should override it in your robot if you want to be informed of this event.

Example:

   public void onBulletMissed(BulletMissedEvent event) {
       out.println("Drat, I missed.");
   }
 

Specified by:
onBulletMissed in interface IBasicEvents
Parameters:
event - the bullet-missed event set by the game
See Also:
BulletMissedEvent, Event

onDeath

public void onDeath(DeathEvent event)
This method is called if your robot dies.

You should override it in your robot if you want to be informed of this event. Actions will have no effect if called from this section. The intent is to allow you to perform calculations or print something out when the robot is killed.

Specified by:
onDeath in interface IBasicEvents
Parameters:
event - the death event set by the game
See Also:
DeathEvent, WinEvent, RoundEndedEvent, BattleEndedEvent, Event

onHitByBullet

public void onHitByBullet(HitByBulletEvent event)
This method is called when your robot is hit by a bullet. You should override it in your robot if you want to be informed of this event.

Example:

   void onHitByBullet(HitByBulletEvent event) {
       out.println(event.getRobotName() + " hit me!");
   }
 

Specified by:
onHitByBullet in interface IBasicEvents
Parameters:
event - the hit-by-bullet event set by the game
See Also:
HitByBulletEvent, Event

onHitRobot

public void onHitRobot(HitRobotEvent event)
This method is called when your robot collides with another robot. You should override it in your robot if you want to be informed of this event.

Example:

   void onHitRobot(HitRobotEvent event) {
       if (event.getBearing() > -90 && event.getBearing() <= 90) {
           back(100);
       } else {
           ahead(100);
       }
   }
 

-- or perhaps, for a more advanced robot --

public void onHitRobot(HitRobotEvent event) { if (event.getBearing() > -90 && event.getBearing() <= 90) { setBack(100); } else { setAhead(100); } }

The angle is relative to your robot's facing. So 0 is straight ahead of you.

This event can be generated if another robot hits you, in which case event.isMyFault() will return false. In this case, you will not be automatically stopped by the game -- but if you continue moving toward the robot you will hit it (and generate another event). If you are moving away, then you won't hit it.

Specified by:
onHitRobot in interface IBasicEvents
Parameters:
event - the hit-robot event set by the game
See Also:
HitRobotEvent, Event

onHitWall

public void onHitWall(HitWallEvent event)
This method is called when your robot collides with a wall. You should override it in your robot if you want to be informed of this event.

The wall at the top of the screen is 0 degrees, right is 90 degrees, bottom is 180 degrees, left is 270 degrees. But this event is relative to your heading, so: The bearing is such that turnRight (event.getBearing()) will point you perpendicular to the wall.

Example:

   void onHitWall(HitWallEvent event) {
       out.println("Ouch, I hit a wall bearing " + event.getBearing() + " degrees.");
   }
 

Specified by:
onHitWall in interface IBasicEvents
Parameters:
event - the hit-wall event set by the game
See Also:
HitWallEvent, Event

onPaint

public void onPaint(Graphics2D g)
This method is called every time the robot is painted. You should override this method if you want to draw items for your robot on the battle field, e.g. targets, virtual bullets etc.

This method is very useful for debugging your robot.

Note that the robot will only be painted if the "Paint" is enabled on the robot's console window; otherwise the robot will never get painted (the reason being that all robots might have graphical items that must be painted, and then you might not be able to tell what graphical items that have been painted for your robot).

Also note that the coordinate system for the graphical context where you paint items fits for the Robocode coordinate system where (0, 0) is at the bottom left corner of the battlefield, where X is towards right and Y is upwards.

Specified by:
onPaint in interface IPaintEvents
Parameters:
g - the graphics context to use for painting graphical items for the robot.
See Also:
Graphics2D

onRobotDeath

public void onRobotDeath(RobotDeathEvent event)
This method is called when another robot dies. You should override it in your robot if you want to be informed of this event.

Specified by:
onRobotDeath in interface IBasicEvents
Parameters:
event - The robot-death event set by the game
See Also:
RobotDeathEvent, Event

onRoundEnded

public void onRoundEnded(RoundEndedEvent event)
This method is called after the end of a round. You should override it in your robot if you want to be informed of this event.

Example:

   public void onRoundEnded(RoundEndedEvent event) {
       out.println("The round has ended");
   }
 

Specified by:
onRoundEnded in interface IBasicEvents3
Parameters:
event - the RoundEndedEvent event set by the game
See Also:
RoundEndedEvent, IBasicEvents2.onBattleEnded(BattleEndedEvent), WinEvent, DeathEvent, Event

onScannedShip

public void onScannedShip(ScannedShipEvent event)
This method is called when your robot sees another robot, i.e. when the robot's radar scan "hits" another robot. You should override it in your robot if you want to be informed of this event. (Almost all robots should override this!)

This is an extension on the onScannedRobot event. Rather then having the bearing from the center of your ship to the other ship. This event contains the bearings for both the front and the back canon. The only thing you have to do is rotate them by the given amount of degrees.

Specified by:
onScannedShip in interface IBasicEvents4
Parameters:
event - the scanned-robot event set by the game
See Also:
IBasicEvents.onScannedRobot(ScannedRobotEvent), ScannedRobotEvent, Event, Rules.RADAR_SCAN_RADIUS

onStatus

public void onStatus(StatusEvent event)
This method is called every turn in a battle round in order to provide the robot status as a complete snapshot of the robot's current state at that specific time.

The main benefit of this method is that you'll automatically receive all current data values of the robot like e.g. the x and y coordinate, heading, gun heat etc., which are grouped into the exact same time/turn.

This is the only way to map the robots data values to a specific time. For example, it is not possible to determine the exact time of the robot's heading by calling first calling Robot.getTime() and then Robot.getHeading() afterwards, as the time might change after between the Robot.getTime() and Robot.getHeading() call.

Specified by:
onStatus in interface IBasicEvents
Parameters:
event - the event containing the robot status at the time it occurred.
See Also:
StatusEvent, Event

onWin

public void onWin(WinEvent event)
This method is called if your robot wins a battle.

Your robot could perform a victory dance here! :-)

Specified by:
onWin in interface IBasicEvents
Parameters:
event - the win event set by the game
See Also:
DeathEvent, RoundEndedEvent, BattleEndedEvent, Event

onMineHitMine

public void onMineHitMine(MineHitMineEvent event)
Triggers when your Mine has hit another Mine.

Specified by:
onMineHitMine in interface IBasicEvents4
Parameters:
event - You can use this event to retrieve the Mine that hit and the Mine that got hit.

onMineHit

public void onMineHit(MineHitEvent event)
Triggers when your Mine has hit a Ship (Can be your own Ship)

Specified by:
onMineHit in interface IBasicEvents4
Parameters:
event - Has information like the Ship you hit, the Mine that hit and the energy left on that Ship.

onHitByMine

public void onHitByMine(HitByMineEvent event)
Triggers when your Ship get hit by a Mine.

Specified by:
onHitByMine in interface IBasicEvents4
Parameters:
event - Contains the Mine that hit you, not much else.

onScannedRobot

public void onScannedRobot(ScannedRobotEvent event)
Deprecated. Use onScannedShip(ScannedShipEvent event) instead.

Description copied from interface: IBasicEvents
This method is called when your robot sees another robot, i.e. when the robot's radar scan "hits" another robot. You should override it in your robot if you want to be informed of this event. (Almost all robots should override this!)

This event is automatically called if there is a robot in range of your radar.

Note that the robot's radar can only see robot within the range defined by Rules.RADAR_SCAN_RADIUS (1200 pixels).

Also not that the bearing of the scanned robot is relative to your robot's heading.

Example:

   void onScannedRobot(ScannedRobotEvent event) {
       // Assuming radar and gun are aligned...
       if (event.getDistance() < 100) {
           fire(3);
       } else {
           fire(1);
       }
   }
 

Note:
The game assists Robots in firing, as follows:

In essence, this means that if you can see a robot, and it doesn't move, then fire will hit it.

AdvancedRobots will NOT be assisted in this manner, and are expected to examine the event to determine if fire() would hit. (i.e. you are spinning your gun around, but by the time you get the event, your gun is 5 degrees past the robot).

Specified by:
onScannedRobot in interface IBasicEvents
Parameters:
event - the scanned-robot event set by the game
See Also:
ScannedRobotEvent, Event, Rules.RADAR_SCAN_RADIUS

getVelocity

public double getVelocity()
Returns the velocity the Ship is going at in knots (pixels per second)

Specified by:
getVelocity in interface IShip
Returns:
the velocity the Ship is going at in knots (pixels per second)

setAhead

public void setAhead(double distance)
Immediately moves your robot ahead (forward) by distance measured in pixels.

This call executes immediately, and does not return until it is complete, i.e. when the remaining distance to move is 0.

If the robot collides with a wall, the move is complete, meaning that the robot will not move any further. If the robot collides with another robot, the move is complete if you are heading toward the other robot.

Note that both positive and negative values can be given as input, where negative values means that the robot is set to move backward instead of forward.

Example:

   // Move the robot 100 pixels forward
   ahead(100);

   // Afterwards, move the robot 50 pixels backward
   ahead(-50);
 

Specified by:
setAhead in interface IShip
Parameters:
distance - the distance to move ahead measured in pixels. If this value is negative, the robot will move back instead of ahead.
See Also:
#back(double), #onHitWall(HitWallEvent), #onHitRobot(HitRobotEvent)

setBack

public void setBack(double distance)
Moves your Ship back by the given number of pixels.

Specified by:
setBack in interface IShip
Parameters:
distance - The distance you want to move backwards in pixels.

getDistanceRemaining

public double getDistanceRemaining()
Returns the distance remaining in the robot's current move measured in pixels.

This call returns both positive and negative values. Positive values means that the robot is currently moving forwards. Negative values means that the robot is currently moving backwards. If the returned value is 0, the robot currently stands still.

Specified by:
getDistanceRemaining in interface IShip
Returns:
the distance remaining in the robot's current move measured in pixels.

getBodyHeadingRadians

public double getBodyHeadingRadians()
Returns the heading of the Ship in Radians. Return value is between 0 and 2*PI, where PI/2 would be equivalent to east.

Specified by:
getBodyHeadingRadians in interface IShip
Returns:
the heading of the Ship in Radians.

getBodyHeadingDegrees

public double getBodyHeadingDegrees()
Returns the heading of the Ship in Degrees. Return value is between 0 and 360, where 90 degrees would be equivalent to east.

Specified by:
getBodyHeadingDegrees in interface IShip
Returns:
the heading of the Ship in Degrees.

getGunHeatComponent

public double getGunHeatComponent(int index)
Returns the gunHeat of the given component. Note: At the moment, you can even get the gunHeat of a Radar, but since it'll always return 0 anyway, I'm not too concerned by this.

Specified by:
getGunHeatComponent in interface IShip
Parameters:
index - The index of the component you want to know the gunHeat of.
Returns:
The gunheat of the given component.

getComponentHeadingDegrees

public double getComponentHeadingDegrees(int index)
Returns the absolute heading of the component in degrees. Return value is between 0 and 360, where 90 degrees would be equivalent to east. The value is NOT relative to the ship; it's relative to the battlefield.

Specified by:
getComponentHeadingDegrees in interface IShip
Parameters:
index - The index of the component you want to know the heading of.
Returns:
The heading of the component in degrees.

getComponentHeadingRadians

public double getComponentHeadingRadians(int index)
Returns the absolute heading of the component in radians.

Specified by:
getComponentHeadingRadians in interface IShip
Parameters:
index - The index of the component you want to know the heading of.
Returns:
The heading of the component in radians.

getX

public double getX()
Returns the X position of the robot. (0,0) is at the bottom left of the battlefield. NOTE: Returns the X value used by the system. Which is the X value of the pivot.

Specified by:
getX in interface IShip
Returns:
the X position of the ship.
See Also:
IShip.getY(), IShip.getXMiddle()

getXMiddle

public double getXMiddle()
Returns the X coordinate of the middle of the Ship. For the X coordinate of the pivot of the ship:

Specified by:
getXMiddle in interface IShip
Returns:
X position of the middle of the ship.
See Also:
IShip.getX()

getXFrontCannon

public double getXFrontCannon()
Description copied from interface: IFrontCannonFunctions
Returns the current X-coordinate of your front cannon

Specified by:
getXFrontCannon in interface IFrontCannonFunctions
Returns:
the current X-coordinate of your front cannon

getXBackCannon

public double getXBackCannon()
Description copied from interface: IBackCannonFunctions
Returns the current X-coordinate of your back cannon

Specified by:
getXBackCannon in interface IBackCannonFunctions
Returns:
the current X-coordinate of your back cannon

getXRadar

public double getXRadar()
Description copied from interface: IRadarFunctions
Returns the current X-coordinate of the Radar

Specified by:
getXRadar in interface IRadarFunctions
Returns:
the current X-coordinate of the Radar

getY

public double getY()
Returns the Y position of the robot. (0,0) is at the bottom left of the battlefield. NOTE: Returns the Y value used by the system. Which is the Y value of the pivot.

Specified by:
getY in interface IShip
Returns:
the Y position of the ship.
See Also:
IShip.getX(), IShip.getYMiddle()

getYMiddle

public double getYMiddle()
Returns the Y coordinate of the middle of the Ship. For the Y coordinate of the pivot of the ship:

Specified by:
getYMiddle in interface IShip
Returns:
Y position of the middle of the ship.
See Also:
IShip.getY()

getYFrontCannon

public double getYFrontCannon()
Description copied from interface: IFrontCannonFunctions
Returns the current Y-coordinate of your front cannon

Specified by:
getYFrontCannon in interface IFrontCannonFunctions
Returns:
the current Y-coordinate of your front cannon

getYBackCannon

public double getYBackCannon()
Description copied from interface: IBackCannonFunctions
Returns the current Y-coordinate of your back cannon

Specified by:
getYBackCannon in interface IBackCannonFunctions
Returns:
the current Y-coordinate of your back cannon

getYRadar

public double getYRadar()
Description copied from interface: IRadarFunctions
Returns the current Y-coordinate of the Radar

Specified by:
getYRadar in interface IRadarFunctions
Returns:
the current Y-coordinate of the Radar

getBattleFieldWidth

public double getBattleFieldWidth()
Returns the width of the current battlefield measured in pixels.

Specified by:
getBattleFieldWidth in interface IShip
Returns:
the width of the current battlefield measured in pixels.

getBattleFieldHeight

public double getBattleFieldHeight()
Returns the height of the current battlefield measured in pixels.

Specified by:
getBattleFieldHeight in interface IShip
Returns:
the height of the current battlefield measured in pixels.

getBodyTurnRemainingDegrees

public double getBodyTurnRemainingDegrees()
Deprecated to avoid confusion Returns the angle remaining in the robots's turn, in degrees.

This call returns both positive and negative values. Positive values means that the robot is currently turning to the right. Negative values means that the robot is currently turning to the left. If the returned value is 0, the robot is currently not turning.

Specified by:
getBodyTurnRemainingDegrees in interface IShip
Returns:
the angle remaining in the robots's turn, in degrees
See Also:
getTurnRemainingRadians(), getDistanceRemaining(), getGunTurnRemaining(), getGunTurnRemainingRadians(), getRadarTurnRemaining(), getRadarTurnRemainingRadians()

getBodyTurnRemainingRadians

public double getBodyTurnRemainingRadians()
Returns the angle remaining in the robot's turn, in radians.

This call returns both positive and negative values. Positive values means that the robot is currently turning to the right. Negative values means that the robot is currently turning to the left.

Specified by:
getBodyTurnRemainingRadians in interface IShip
Returns:
the angle remaining in the robot's turn, in radians

getTime

public long getTime()
Returns the game time of the current round, where the time is equal to the current turn in the round.

A battle consists of multiple rounds.

Time is reset to 0 at the beginning of every round.

Specified by:
getTime in interface IShip
Returns:
the game time/turn of the current round.

getEnergy

public double getEnergy()
Returns the robot's current energy.

Specified by:
getEnergy in interface IShip
Returns:
the robot's current energy.

addCustomEvent

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 call 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);
 

Parameters:
condition - the condition that must be met.
Throws:
NullPointerException - if the condition parameter has been set to null.
See Also:
Condition, removeCustomEvent(Condition)

removeCustomEvent

public void removeCustomEvent(Condition condition)
Removes a custom event that was previously added by calling 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);
 

Parameters:
condition - the condition that was previous added and that must be removed now.
Throws:
NullPointerException - if the condition parameter has been set to null.
See Also:
Condition, addCustomEvent(Condition)

clearAllEvents

public void clearAllEvents()
Clears out any pending events in the robot's event queue immediately.

See Also:
getAllEvents()

getAllEvents

public Vector<Event> getAllEvents()
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
See Also:
Event, clearAllEvents(), getStatusEvents(), getScannedRobotEvents(), getBulletHitEvents(), getBulletMissedEvents(), getBulletHitBulletEvents(), getRobotDeathEvents()

getBulletHitBulletEvents

public Vector<BulletHitBulletEvent> getBulletHitBulletEvents()
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
See Also:
onBulletHitBullet(BulletHitBulletEvent), BulletHitBulletEvent, getAllEvents()

getBulletHitEvents

public Vector<BulletHitEvent> getBulletHitEvents()
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
See Also:
onBulletHit(BulletHitEvent), BulletHitEvent, getAllEvents()

getBulletMissedEvents

public Vector<BulletMissedEvent> getBulletMissedEvents()
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
See Also:
onBulletMissed(BulletMissedEvent), BulletMissedEvent, getAllEvents()

getEventPriority

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:

   RoundEndedEvent:      100 (reserved)
   BattleEndedEvent:     100 (reserved)
   WinEvent:             100 (reserved)
   SkippedTurnEvent:     100 (reserved)
   StatusEvent:           99
   Key and mouse events:  98
   CustomEvent:           80 (default value)
   MessageEvent:          75
   RobotDeathEvent:       70
   BulletMissedEvent:     60
   BulletHitBulletEvent:  55
   BulletHitEvent:        50
   HitByBulletEvent:      40
   HitWallEvent:          30
   HitRobotEvent:         20
   ScannedRobotEvent:     10
   PaintEvent:             5
   DeathEvent:            -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)

getHitByBulletEvents

public Vector<HitByBulletEvent> getHitByBulletEvents()
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
See Also:
onHitByBullet(HitByBulletEvent), HitByBulletEvent, getAllEvents()

getHitRobotEvents

public Vector<HitRobotEvent> getHitRobotEvents()
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()

getHitWallEvents

public Vector<HitWallEvent> getHitWallEvents()
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()

getRobotDeathEvents

public Vector<RobotDeathEvent> getRobotDeathEvents()
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
See Also:
onRobotDeath(RobotDeathEvent), RobotDeathEvent, getAllEvents()

getScannedRobotEvents

public Vector<ScannedRobotEvent> getScannedRobotEvents()
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
See Also:
onScannedRobot(ScannedRobotEvent), ScannedRobotEvent, getAllEvents()

getStatusEvents

public Vector<StatusEvent> getStatusEvents()
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()

setEventPriority

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:

         WinEvent:             100 (reserved)
         SkippedTurnEvent:     100 (reserved)
   StatusEvent:           99
         CustomEvent:           80
         MessageEvent:          75
         RobotDeathEvent:       70
         BulletMissedEvent:     60
         BulletHitBulletEvent:  55
         BulletHitEvent:        50
         HitByBulletEvent:      40
         HitWallEvent:          30
         HitRobotEvent:         20
         ScannedRobotEvent:     10
   PaintEvent:             5
         DeathEvent:            -1 (reserved)
 

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).

Parameters:
eventClass - the name of the event class (string) to set the priority for
priority - 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.
See Also:
getEventPriority(String), setInterruptible(boolean)

setInterruptible

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);
       ahead(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.
       out.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
See Also:
setEventPriority(String, int), onScannedRobot(ScannedRobotEvent)

setResume

public void setResume()
Sets the robot to resume the movement stopped by stop() or setStop(), if any.

This call returns immediately, and will not execute until you call execute() or take an action that executes.

See Also:
resume(), stop(), stop(boolean), setStop(), setStop(boolean), execute()

setStop

public 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.

If there is already movement saved from a previous stop, this will have no effect.

This call is equivalent to calling setStop(false);

See Also:
stop(), stop(boolean), resume(), setResume(), setStop(boolean), execute()

setStop

public 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.

If there is already movement saved from a previous stop, you can overwrite it by calling setStop(true).

Parameters:
overwrite - true if the movement saved from a previous stop should be overwritten; false otherwise.
See Also:
stop(), stop(boolean), resume(), setResume(), setStop(), execute()

getRobotRunnable

public Runnable getRobotRunnable()
This method is called by the game to invoke the run() method of your robot, where the program of your robot is implemented.

Specified by:
getRobotRunnable in interface IBasicRobot
Returns:
a runnable implementation
See Also:
Runnable.run()

getBasicEventListener

public IBasicEvents getBasicEventListener()
This method is called by the game to notify this robot about basic robot event. Hence, this method must be implemented so it returns your IBasicEvents listener.

Specified by:
getBasicEventListener in interface IBasicRobot
Returns:
listener to basic events or null if this robot should not receive the notifications.

run

public void run()
This is the method you have to override to create your own ship.

Specified by:
run in interface Runnable

getPaintEventListener

public final IPaintEvents getPaintEventListener()
Description copied from interface: IPaintRobot
This method is called by the game to notify this robot about painting events. Hence, this method must be implemented so it returns your IPaintEvents listener.

Specified by:
getPaintEventListener in interface IPaintRobot
Returns:
listener to paint events or null if this robot should not receive the notifications.

onSkippedTurn

public void onSkippedTurn(SkippedTurnEvent event)
This method is called if the robot is using too much time between actions. When this event occur, the robot's turn is skipped, meaning that it cannot take action anymore in this turn.

If you receive 30 skipped turn event, your robot will be removed from the round and loose the round.

You will only receive this event after taking an action. So a robot in an infinite loop will not receive any events, and will simply be stopped.

No correctly working, reasonable robot should ever receive this event unless it is using too many CPU cycles.

Specified by:
onSkippedTurn in interface IAdvancedEvents
Parameters:
event - the skipped turn event set by the game
See Also:
SkippedTurnEvent, Event

onCustomEvent

public void onCustomEvent(CustomEvent event)
This method is called when a custom condition is met.

See the sample robots for examples of use, e.g. the sample.Target robot.

Specified by:
onCustomEvent in interface IAdvancedEvents
Parameters:
event - the custom event that occurred
See Also:
AdvancedRobot.addCustomEvent(robocode.Condition), CustomEvent, Event

getAdvancedEventListener

public final IAdvancedEvents getAdvancedEventListener()
Do not call this method!

This method is called by the game to notify this robot about advanced robot event. Hence, this method must be implemented so it returns your IAdvancedEvents listener.

Specified by:
getAdvancedEventListener in interface IAdvancedRobot
Returns:
listener to advanced events or null if this robot should not receive the notifications.

placeMine

public Mine placeMine(double power)
Parameters:
power - The power of the mine you want to place

setMineComponentColor

public void setMineComponentColor(Color color)

getDataDirectory

public File getDataDirectory()
Returns a file representing a data directory for the robot, which can be written to using RobocodeFileOutputStream or RobocodeFileWriter.

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
See Also:
getDataFile(String), RobocodeFileOutputStream, RobocodeFileWriter

getDataFile

public File getDataFile(String filename)
Returns a file in your data directory that you can write to using 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.

Parameters:
filename - the file name of the data file for your robot
Returns:
a file representing the data file for your robot or null if the data file could not be created due to an error.
See Also:
getDataDirectory(), RobocodeFileOutputStream, RobocodeFileWriter

getDataQuotaAvailable

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)

waitFor

public void waitFor(Condition condition)
Does not return until a condition is met, i.e. when a Condition.test() returns true.

This call executes immediately.

See the sample.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()

getOthers

public int getOthers()
Returns how many opponents that are left in the current round.

Returns:
how many opponents that are left in the current round.

stop

public void stop()
Immediately stops all movement, and saves it for a call to resume(). If there is already movement saved from a previous stop, this will have no effect.

This method is equivalent to #stop(false).

See Also:
resume(), stop(boolean)

stop

public void stop(boolean overwrite)
Immediately stops all movement, and saves it for a call to resume(). If there is already movement saved from a previous stop, you can overwrite it by calling stop(true).

Parameters:
overwrite - If there is already movement saved from a previous stop, you can overwrite it by calling stop(true).
See Also:
resume(), stop()

resume

public void resume()
Immediately resumes the movement you stopped by stop(), if any.

This call executes immediately, and does not return until it is complete.

See Also:
stop(), stop(boolean)

setCourseRadians

public void setCourseRadians(double angle)
Sets the course towards the specified heading.

Specified by:
setCourseRadians in interface IShip
Parameters:
angle - The angle in radians to which we want to set course. (0 = North, PI/2 = East, etc)


Copyright © 2015 Robocode. All Rights Reserved.