Package robocode

Class JuniorRobot

All Implemented Interfaces:
Runnable, IBasicRobot, IJuniorRobot

public class JuniorRobot extends _RobotBase implements IJuniorRobot
This is the simplest robot type, which is simpler than the Robot and AdvancedRobot classes. The JuniorRobot has a simplified model, in purpose of teaching programming skills to inexperienced in programming students. The simplified robot model will keep player from overwhelming of Robocode's rules, programming syntax and programming concept.

Instead of using getters and setters, public fields are provided for receiving information like the last scanned robot, the coordinate of the robot etc.

All methods on this class are blocking calls, i.e. they do not return before their action has been completed and will at least take one turn to execute. However, setting colors is executed immediately and does not cost a turn to perform.

Since:
1.4
Author:
Nutch Poovarawan from Cubic Creative (designer), Flemming N. Larsen (original), Pavel Savara (contributor)
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The color black (0x000000)
    static final int
    The color blue (0x0000FF)
    static final int
    The color brown (0x8B4513)
    int
    Current energy of this robot, where 100 means full energy and 0 means no energy (dead).
    int
    Contains the height of the battlefield.
    int
    Contains the width of the battlefield.
    static final int
    The color gray (0x808080)
    static final int
    The color green (0x008000)
    int
    Current gun heading angle of this robot compared to its body (in degrees).
    int
    Current gun heading angle of this robot (in degrees).
    boolean
    Flag specifying if the gun is ready to fire, i.e.
    int
    Current heading angle of this robot (in degrees).
    int
    Latest angle from where this robot was hit by a bullet (in degrees).
    int
    Latest angle from where this robot was hit by a bullet (in degrees) compared to the body of this robot.
    int
    Latest angle where this robot has hit another robot (in degrees).
    int
    Latest angle where this robot has hit another robot (in degrees) compared to the body of this robot.
    int
    Latest angle where this robot has hit a wall (in degrees).
    int
    Latest angle where this robot has hit a wall (in degrees) compared to the body of this robot.
    static final int
    The color orange (0xFFA500)
    int
    Current number of other robots on the battle field.
    static final int
    The color purple (0x800080)
    static final int
    The color red (0xFF0000)
    int
    Current horizontal location of this robot (in pixels).
    int
    Current vertical location of this robot (in pixels).
    int
    Current angle to the scanned nearest other robot (in degrees).
    int
    Current angle to the scanned nearest other robot (in degrees) compared to the body of this robot.
    int
    Current distance to the scanned nearest other robot (in pixels).
    int
    Current energy of scanned nearest other robot.
    int
    Current heading of the scanned nearest other robot (in degrees).
    int
    Current velocity of the scanned nearest other robot.
    static final int
    The color white (0xFFFFFF)
    static final int
    The color yellow (0xFFFF00)

    Fields inherited from class robocode._RobotBase

    out
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    ahead(int distance)
    Moves this robot forward by pixels.
    void
    back(int distance)
    Moves this robot backward by pixels.
    void
    bearGunTo(int angle)
    Turns the gun to the specified angle (in degrees) relative to body of this robot.
    void
    Skips a turn.
    void
    doNothing(int turns)
    Skips the specified number of turns.
    void
    Fires a bullet with the default power of 1.
    void
    fire(double power)
    Fires a bullet with the specified bullet power, which is between 0.1 and 3 where 3 is the maximum bullet power.
    Do not call this method!
    final Runnable
    Do not call this method!
    void
    This event methods is called from the game when this robot has been hit by another robot's bullet.
    void
    This event methods is called from the game when a bullet from this robot has hit another robot.
    void
    This event methods is called from the game when this robot has hit a wall.
    void
    This event method is called from the game when the radar detects another robot.
    void
    run()
    The main method in every robot.
    void
    setColors(int bodyColor, int gunColor, int radarColor)
    Sets the colors of the robot.
    void
    setColors(int bodyColor, int gunColor, int radarColor, int bulletColor, int scanArcColor)
    Sets the colors of the robot.
    void
    turnAheadLeft(int distance, int degrees)
    Moves this robot forward by pixels and turns this robot left by degrees at the same time.
    void
    turnAheadRight(int distance, int degrees)
    Moves this robot forward by pixels and turns this robot right by degrees at the same time.
    void
    turnBackLeft(int distance, int degrees)
    Moves this robot backward by pixels and turns this robot left by degrees at the same time.
    void
    turnBackRight(int distance, int degrees)
    Moves this robot backward by pixels and turns this robot right by degrees at the same time.
    void
    turnGunLeft(int degrees)
    Turns the gun left by degrees.
    void
    turnGunRight(int degrees)
    Turns the gun right by degrees.
    void
    turnGunTo(int angle)
    Turns the gun to the specified angle (in degrees).
    void
    turnLeft(int degrees)
    Turns this robot left by degrees.
    void
    turnRight(int degrees)
    Turns this robot right by degrees.
    void
    turnTo(int angle)
    Turns this robot to the specified angle (in degrees).

    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
  • Field Details

  • Constructor Details

    • JuniorRobot

      public JuniorRobot()
  • Method Details

    • ahead

      public void ahead(int distance)
      Moves this robot forward by pixels.
      Parameters:
      distance - the amount of pixels to move forward
      See Also:
    • back

      public void back(int distance)
      Moves this robot backward by pixels.
      Parameters:
      distance - the amount of pixels to move backward
      See Also:
    • bearGunTo

      public void bearGunTo(int angle)
      Turns the gun to the specified angle (in degrees) relative to body of this robot. The gun will turn to the side with the shortest delta angle to the specified angle.
      Parameters:
      angle - the angle to turn the gun to relative to the body of this robot
      See Also:
    • doNothing

      public void doNothing()
      Skips a turn.
      See Also:
    • doNothing

      public void doNothing(int turns)
      Skips the specified number of turns.
      Parameters:
      turns - the number of turns to skip
      See Also:
    • fire

      public void fire()
      Fires a bullet with the default power of 1. If the gun heat is more than 0 and hence cannot fire, this method will suspend until the gun is ready to fire, and then fire a bullet.
      See Also:
    • fire

      public void fire(double power)
      Fires a bullet with the specified bullet power, which is between 0.1 and 3 where 3 is the maximum bullet power. If the gun heat is more than 0 and hence cannot fire, this method will suspend until the gun is ready to fire, and then fire a bullet.
      Parameters:
      power - between 0.1 and 3
      See Also:
    • getBasicEventListener

      public final IBasicEvents getBasicEventListener()
      Do not call this method!

      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.
    • getRobotRunnable

      public final Runnable getRobotRunnable()
      Do not call this method!

      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:
    • onHitByBullet

      public void onHitByBullet()
      This event methods is called from the game when this robot has been hit by another robot's bullet. When this event occurs the hitByBulletAngle and hitByBulletBearing fields values are automatically updated.
      See Also:
    • onHitRobot

      public void onHitRobot()
      This event methods is called from the game when a bullet from this robot has hit another robot. When this event occurs the hitRobotAngle and hitRobotBearing fields values are automatically updated.
      See Also:
    • onHitWall

      public void onHitWall()
      This event methods is called from the game when this robot has hit a wall. When this event occurs the hitWallAngle and hitWallBearing fields values are automatically updated.
      See Also:
    • onScannedRobot

      public void onScannedRobot()
      This event method is called from the game when the radar detects another robot. When this event occurs the scannedDistance, scannedAngle, scannedBearing, and scannedEnergy field values are automatically updated.
      See Also:
    • run

      public void run()
      The main method in every robot. You must override this to set up your robot's basic behavior.

      Example:

         // A basic robot that moves around in a square
         public void run() {
             ahead(100);
             turnRight(90);
         }
       
      This method is automatically re-called when it has returned.
      Specified by:
      run in interface Runnable
    • setColors

      public void setColors(int bodyColor, int gunColor, int radarColor)
      Sets the colors of the robot. The color values are RGB values. You can use the colors that are already defined for this class.
      Parameters:
      bodyColor - the RGB color value for the body
      gunColor - the RGB color value for the gun
      radarColor - the RGB color value for the radar
      See Also:
    • setColors

      public void setColors(int bodyColor, int gunColor, int radarColor, int bulletColor, int scanArcColor)
      Sets the colors of the robot. The color values are RGB values. You can use the colors that are already defined for this class.
      Parameters:
      bodyColor - the RGB color value for the body
      gunColor - the RGB color value for the gun
      radarColor - the RGB color value for the radar
      bulletColor - the RGB color value for the bullets
      scanArcColor - the RGB color value for the scan arc
      See Also:
    • turnAheadLeft

      public void turnAheadLeft(int distance, int degrees)
      Moves this robot forward by pixels and turns this robot left by degrees at the same time. The robot will move in a curve that follows a perfect circle, and the moving and turning will end at the same time.

      Note that the max. velocity and max. turn rate is automatically adjusted, which means that the robot will move slower the sharper the turn is compared to the distance.

      Parameters:
      distance - the amount of pixels to move forward
      degrees - the amount of degrees to turn to the left
      See Also:
    • turnAheadRight

      public void turnAheadRight(int distance, int degrees)
      Moves this robot forward by pixels and turns this robot right by degrees at the same time. The robot will move in a curve that follows a perfect circle, and the moving and turning will end at the same time.

      Note that the max. velocity and max. turn rate is automatically adjusted, which means that the robot will move slower the sharper the turn is compared to the distance.

      Parameters:
      distance - the amount of pixels to move forward
      degrees - the amount of degrees to turn to the right
      See Also:
    • turnBackLeft

      public void turnBackLeft(int distance, int degrees)
      Moves this robot backward by pixels and turns this robot left by degrees at the same time. The robot will move in a curve that follows a perfect circle, and the moving and turning will end at the same time.

      Note that the max. velocity and max. turn rate is automatically adjusted, which means that the robot will move slower the sharper the turn is compared to the distance.

      Parameters:
      distance - the amount of pixels to move backward
      degrees - the amount of degrees to turn to the left
      See Also:
    • turnBackRight

      public void turnBackRight(int distance, int degrees)
      Moves this robot backward by pixels and turns this robot right by degrees at the same time. The robot will move in a curve that follows a perfect circle, and the moving and turning will end at the same time.

      Note that the max. velocity and max. turn rate is automatically adjusted, which means that the robot will move slower the sharper the turn is compared to the distance.

      Parameters:
      distance - the amount of pixels to move backward
      degrees - the amount of degrees to turn to the right
      See Also:
    • turnGunLeft

      public void turnGunLeft(int degrees)
      Turns the gun left by degrees.
      Parameters:
      degrees - the amount of degrees to turn the gun to the left
      See Also:
    • turnGunRight

      public void turnGunRight(int degrees)
      Turns the gun right by degrees.
      Parameters:
      degrees - the amount of degrees to turn the gun to the right
      See Also:
    • turnGunTo

      public void turnGunTo(int angle)
      Turns the gun to the specified angle (in degrees). The gun will turn to the side with the shortest delta angle to the specified angle.
      Parameters:
      angle - the angle to turn the gun to
      See Also:
    • turnLeft

      public void turnLeft(int degrees)
      Turns this robot left by degrees.
      Parameters:
      degrees - the amount of degrees to turn to the left
      See Also:
    • turnRight

      public void turnRight(int degrees)
      Turns this robot right by degrees.
      Parameters:
      degrees - the amount of degrees to turn to the right
      See Also:
    • turnTo

      public void turnTo(int angle)
      Turns this robot to the specified angle (in degrees). The robot will turn to the side with the shortest delta angle to the specified angle.
      Parameters:
      angle - the angle to turn this robot to
      See Also: