Class RateControlRobot
- All Implemented Interfaces:
Runnable
,IAdvancedEvents
,IAdvancedRobot
,IBasicEvents
,IBasicEvents2
,IBasicEvents3
,IBasicRobot
,IInteractiveEvents
,IInteractiveRobot
,IPaintEvents
,IPaintRobot
,ITeamEvents
,ITeamRobot
You can set the rate for:
- velocity - pixels per turn
- robot turn - radians per turn
- gun rotation - radians per turn
- radar rotation - radians per turn
Note: When calling setVelocityRate()
, setTurnRate()
, setGunRotationRate()
,
setRadarRotationRate()
and variants, Any previous calls to "movement" functions outside of
RateControlRobot
, such as setAhead()
, setTurnLeft()
,
setTurnRadarRightRadians()
and similar will be overridden when calling the
execute()
on this robot class.
Look into the source code for the sample.VelociRobot
in order to see how to use this
robot type.
- Since:
- 1.7.1.3
- Author:
- Joshua Galecki (original), Flemming N. Larsen (contributor)
- See Also:
-
Field Summary
Fields inherited from class robocode._RobotBase
out
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
execute()
Executes any pending actions, or continues executing actions that are in process.double
Gets the gun's clockwise rotation per turn, in degrees.double
Gets the gun's clockwise rotation per turn, in radians.double
Gets the radar's clockwise rotation per turn, in degrees.double
Gets the radar's clockwise rotation per turn, in radians.double
Gets the robot's clockwise rotation per turn, in degrees.double
Gets the robot's clockwise rotation per turn, in radians.double
Returns the speed the robot will move, in pixels per turn.void
setGunRotationRate
(double gunRotationRate) Sets the gun's clockwise (right) rotation per turn, in degrees.void
setGunRotationRateRadians
(double gunRotationRate) Sets the gun's clockwise (right) rotation per turn, in radians.void
setRadarRotationRate
(double radarRotationRate) Sets the radar's clockwise (right) rotation per turn, in degrees.void
setRadarRotationRateRadians
(double radarRotationRate) Sets the radar's clockwise (right) rotation per turn, in radians.void
setTurnRate
(double turnRate) Sets the robot's clockwise (right) rotation per turn, in degrees.void
setTurnRateRadians
(double turnRate) Sets the robot's clockwise (right) rotation per turn, in radians.void
setVelocityRate
(double velocityRate) Sets the speed the robot will move (forward), in pixels per turn.Methods inherited from class robocode.TeamRobot
broadcastMessage, getMessageEvents, getTeamEventListener, getTeammates, isTeammate, onMessageReceived, sendMessage
Methods inherited from class robocode.AdvancedRobot
addCustomEvent, clearAllEvents, getAdvancedEventListener, getAllEvents, getBulletHitBulletEvents, getBulletHitEvents, getBulletMissedEvents, getDataDirectory, getDataFile, getDataQuotaAvailable, getDistanceRemaining, getEventPriority, getGunHeadingRadians, getGunTurnRemaining, getGunTurnRemainingRadians, getHeadingRadians, getHitByBulletEvents, getHitRobotEvents, getHitWallEvents, getRadarHeadingRadians, getRadarTurnRemaining, getRadarTurnRemainingRadians, getRobotDeathEvents, getScannedRobotEvents, getStatusEvents, getTurnRemaining, getTurnRemainingRadians, isAdjustGunForRobotTurn, isAdjustRadarForGunTurn, isAdjustRadarForRobotTurn, onCustomEvent, onDeath, onSkippedTurn, removeCustomEvent, setAhead, setBack, setEventPriority, setFire, setFireBullet, setInterruptible, setMaxTurnRate, setMaxVelocity, setResume, setStop, setStop, setTurnGunLeft, setTurnGunLeftRadians, setTurnGunRight, setTurnGunRightRadians, setTurnLeft, setTurnLeftRadians, setTurnRadarLeft, setTurnRadarLeftRadians, setTurnRadarRight, setTurnRadarRightRadians, setTurnRight, setTurnRightRadians, turnGunLeftRadians, turnGunRightRadians, turnLeftRadians, turnRadarLeftRadians, turnRadarRightRadians, turnRightRadians, waitFor
Methods inherited from class robocode._AdvancedRobot
endTurn, getGunHeadingDegrees, getHeadingDegrees, getMaxWaitCount, getRadarHeadingDegrees, getWaitCount, setTurnGunLeftDegrees, setTurnGunRightDegrees, setTurnLeftDegrees, setTurnRadarLeftDegrees, setTurnRadarRightDegrees, setTurnRightDegrees, turnGunLeftDegrees, turnGunRightDegrees, turnLeftDegrees, turnRadarLeftDegrees, turnRadarRightDegrees, turnRightDegrees
Methods inherited from class robocode.Robot
ahead, back, doNothing, fire, fireBullet, getBasicEventListener, getBattleFieldHeight, getBattleFieldWidth, getEnergy, getGraphics, getGunCoolingRate, getGunHeading, getGunHeat, getHeading, getHeight, getInteractiveEventListener, getName, getNumRounds, getNumSentries, getOthers, getPaintEventListener, getRadarHeading, getRobotRunnable, getRoundNum, getSentryBorderSize, getTime, getVelocity, getWidth, getX, getY, onBattleEnded, onBulletHit, onBulletHitBullet, onBulletMissed, onHitByBullet, onHitRobot, onHitWall, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragged, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onMouseWheelMoved, onPaint, onRobotDeath, onRoundEnded, onScannedRobot, onStatus, onWin, resume, run, scan, setAdjustGunForRobotTurn, setAdjustRadarForGunTurn, setAdjustRadarForRobotTurn, setAllColors, setBodyColor, setBulletColor, setColors, setColors, setDebugProperty, setGunColor, setRadarColor, setScanColor, stop, stop, turnGunLeft, turnGunRight, turnLeft, turnRadarLeft, turnRadarRight, turnRight
Methods inherited from class robocode._Robot
getBattleNum, getGunCharge, getGunImageName, getLife, getNumBattles, getRadarImageName, getRobotImageName, setGunImageName, setRadarImageName, setRobotImageName
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.IAdvancedRobot
getAdvancedEventListener
Methods inherited from interface robocode.robotinterfaces.IBasicRobot
getBasicEventListener, getRobotRunnable, setOut, setPeer
-
Constructor Details
-
RateControlRobot
public RateControlRobot()
-
-
Method Details
-
setVelocityRate
public void setVelocityRate(double velocityRate) Sets the speed the robot will move (forward), in pixels per turn.This call returns immediately, and will not execute until you call execute() or take an action that executes.
Note that both positive and negative values can be given as input, where negative values means that the robot will move backwards
Example:
// Set the robot to move forward 2 pixels per turn setVelocityRate(2); // Set the robot to move backwards 8 pixels per turn // (overrides the previous order) setVelocityRate(-8); ... // Executes the last setVelocityRate() execute();
Note: This method overrulesAdvancedRobot.setAhead(double)
andAdvancedRobot.setBack(double)
.- Parameters:
velocityRate
- pixels per turn the robot will move.- See Also:
-
getVelocityRate
public double getVelocityRate()Returns the speed the robot will move, in pixels per turn. Positive values means that the robot will move forward. Negative values means that the robot will move backwards. If the value is 0, the robot will stand still.- Returns:
- The speed of the robot in pixels per turn
- See Also:
-
setTurnRate
public void setTurnRate(double turnRate) Sets the robot's clockwise (right) rotation per turn, in degrees.This call returns immediately, and will not execute until you call execute() or take an action that executes.
Note that both positive and negative values can be given as input, where negative values means that the robot turns counterclockwise (left)
Example:
// Set the robot to turn right 10 degrees per turn setTurnRate(10); // Set the robot to turn left 4 degrees per turn // (overrides the previous order) setTurnRate(-5); ... // Executes the last setTurnRate() execute();
- Parameters:
turnRate
- angle of the clockwise rotation, in degrees.- See Also:
-
getTurnRate
public double getTurnRate()Gets the robot's clockwise rotation per turn, in degrees. Positive values means that the robot will turn to the right. Negative values means that the robot will turn to the left. If the value is 0, the robot will not turn.- Returns:
- Angle of the clockwise rotation, in degrees.
- See Also:
-
setTurnRateRadians
public void setTurnRateRadians(double turnRate) Sets the robot's clockwise (right) rotation per turn, in radians.This call returns immediately, and will not execute until you call execute() or take an action that executes.
Note that both positive and negative values can be given as input, where negative values means that the robot turns counterclockwise (left)
Example:
// Set the robot to turn right pi / 32 radians per turn setTurnRateRadians(Math.PI / 32); // Set the robot to turn left pi / 20 radians per turn // (overrides the previous order) setTurnRateRadians(-Math.PI / 20); ... // Executes the last setTurnRateRadians() execute();
- Parameters:
turnRate
- angle of the clockwise rotation, in radians.- See Also:
-
getTurnRateRadians
public double getTurnRateRadians()Gets the robot's clockwise rotation per turn, in radians. Positive values means that the robot will turn to the right. Negative values means that the robot will turn to the left. If the value is 0, the robot will not turn.- Returns:
- Angle of the clockwise rotation, in radians.
- See Also:
-
setGunRotationRate
public void setGunRotationRate(double gunRotationRate) Sets the gun's clockwise (right) rotation per turn, in degrees.This call returns immediately, and will not execute until you call execute() or take an action that executes.
Note that both positive and negative values can be given as input, where negative values means that the gun turns counterclockwise (left)
Example:
// Set the gun to turn right 15 degrees per turn setGunRotationRate(15); // Set the gun to turn left 9 degrees per turn // (overrides the previous order) setGunRotationRate(-9); ... // Executes the last setGunRotationRate() execute();
- Parameters:
gunRotationRate
- angle of the clockwise rotation, in degrees.- See Also:
-
getGunRotationRate
public double getGunRotationRate()Gets the gun's clockwise rotation per turn, in degrees. Positive values means that the gun will turn to the right. Negative values means that the gun will turn to the left. If the value is 0, the gun will not turn.- Returns:
- Angle of the clockwise rotation, in degrees.
- See Also:
-
setGunRotationRateRadians
public void setGunRotationRateRadians(double gunRotationRate) Sets the gun's clockwise (right) rotation per turn, in radians.This call returns immediately, and will not execute until you call execute() or take an action that executes.
Note that both positive and negative values can be given as input, where negative values means that the gun turns counterclockwise (left)
Example:
// Set the gun to turn right pi / 16 radians per turn setGunRotationRateRadians(Math.PI / 16); // Set the gun to turn left pi / 12 radians per turn // (overrides the previous order) setGunRotationRateRadians(-Math.PI / 12); ... // Executes the last setGunRotationRateRadians() execute();
- Parameters:
gunRotationRate
- angle of the clockwise rotation, in radians.- See Also:
-
getGunRotationRateRadians
public double getGunRotationRateRadians()Gets the gun's clockwise rotation per turn, in radians. Positive values means that the gun will turn to the right. Negative values means that the gun will turn to the left. If the value is 0, the gun will not turn.- Returns:
- Angle of the clockwise rotation, in radians.
- See Also:
-
setRadarRotationRate
public void setRadarRotationRate(double radarRotationRate) Sets the radar's clockwise (right) rotation per turn, in degrees.This call returns immediately, and will not execute until you call execute() or take an action that executes.
Note that both positive and negative values can be given as input, where negative values means that the radar turns counterclockwise (left)
Example:
// Set the radar to turn right 45 degrees per turn setRadarRotationRate(45); // Set the radar to turn left 15 degrees per turn // (overrides the previous order) setRadarRotationRate(-15); ... // Executes the last setRadarRotationRate() execute();
- Parameters:
radarRotationRate
- angle of the clockwise rotation, in degrees.- See Also:
-
getRadarRotationRate
public double getRadarRotationRate()Gets the radar's clockwise rotation per turn, in degrees. Positive values means that the radar will turn to the right. Negative values means that the radar will turn to the left. If the value is 0, the radar will not turn.- Returns:
- Angle of the clockwise rotation, in degrees.
- See Also:
-
setRadarRotationRateRadians
public void setRadarRotationRateRadians(double radarRotationRate) Sets the radar's clockwise (right) rotation per turn, in radians.This call returns immediately, and will not execute until you call execute() or take an action that executes.
Note that both positive and negative values can be given as input, where negative values means that the radar turns counterclockwise (left)
Example:
// Set the radar to turn right pi / 4 radians per turn setRadarRotationRateRadians(Math.PI / 4); // Set the radar to turn left pi / 8 radians per turn // (overrides the previous order) setRadarRotationRateRadians(-Math.PI / 8); ... // Executes the last setRadarRotationRateRadians() execute();
- Parameters:
radarRotationRate
- angle of the clockwise rotation, in radians.- See Also:
-
getRadarRotationRateRadians
public double getRadarRotationRateRadians()Gets the radar's clockwise rotation per turn, in radians. Positive values means that the radar will turn to the right. Negative values means that the radar will turn to the left. If the value is 0, the radar will not turn.- Returns:
- Angle of the clockwise rotation, in radians.
- See Also:
-
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 advanced robots must call this function in order to execute pending set* calls like e.g.
setVelocityRate()
,setFire()
,setTurnRate()
etc. Otherwise, these calls will never get executed.Any previous calls to "movement" functions outside of
RateControlRobot
, such assetAhead()
,setTurnLeft()
,setTurnRadarLeftRadians()
etc. will be overridden when this method is called on this robot class.In this example the robot will move while turning:
setVelocityRate(6); setTurnRate(7); while (true) { execute(); }
- Overrides:
execute
in classAdvancedRobot
-