robocraft.player
Class AbstractRobotPlayer

java.lang.Object
  extended byrobocraft.player.AbstractRobotPlayer
All Implemented Interfaces:
GameConstants

public abstract class AbstractRobotPlayer
extends java.lang.Object
implements GameConstants

This is the class that contestants will need to extend and implement (in a file RobotPlayer.java). Player actions are performed by calling methods of this class (which inherently remembers which robot ID is associated with it). In addition, subclasses may reference the same methods in GameObject or Robot, but without worrying about exceptions being thrown. For example, call this.getTeam() to get your own team without worrying about an exception being thrown. (Instead of calling getRobot().getTeam()).


Field Summary
 
Fields inherited from interface robocraft.common.GameConstants
BROADCAST_COST_PER_BYTE, BROADCAST_FIXED_COST, DEFAULT_DEBUG_ENABLED, DEFAULT_MAP, DEFAULT_SERVER_HOST, DEFAULT_SERVER_PORT, DEFAULT_SILENCEA, DEFAULT_SILENCEB, DEFAULT_TEAMA, DEFAULT_TEAMB, EXCEPTION_ENERGON_COST, FALLOUT_FRACTION, MAX_MINE_POWER, MIN_MINE_POWER, MINE_DAMAGE_FACTOR, MINE_DELAY_ROUNDS, MOVING_DAMAGE_REDUCTION, ROBOT_TYPE_LIMIT, ROUND_ENERGON_BONUS, ROUNDS_PER_SHRINK, SERVER_PORT, TEAM_TOTAL_LIMIT, YIELD_ENERGON_BONUS
 
Constructor Summary
AbstractRobotPlayer()
           
 
Method Summary
 void attackAir(MapLocation targetLoc)
          Initiate an attack on the AIR in a specified location.
 void attackGround(MapLocation targetLoc)
          Initiate an attack on the GROUND in a specified location.
 void broadcastMessage(Message msg)
          Broadcasts a message to all Robots currently in your broadcast range.
static boolean canAttackAir()
          wrapper for corresponding Robot method; does not throw an exception
static boolean canAttackGround()
          wrapper for corresponding Robot method; does not throw an exception
static boolean canAttackSquare(MapLocation loc)
          wrapper for corresponding Robot method that does not throw an exception
static boolean canMove(Direction dir)
          wrapper for corresponding Robot method; does not throw an exception.
static boolean canSenseObject(GameObject obj)
          wrapper for corresponding Robot method; does not throw an exception
static boolean canSenseSquare(MapLocation loc)
          wrapper for corresponding Robot method; does not throw an exception
 void depositFlag()
          Deposit the flag you are carrying into the square in front of you.
 Robot getAirRobotAtLocation(MapLocation loc)
          Sense any Robots IN THE AIR at this location.
static double getAttackPower()
          wrapper for corresponding Robot method; does not throw an exception
static int getBytecodesPerRound()
          wrapper for corresponding Robot method; does not throw an exception
static ActionType getCurrentAction()
          wrapper for corresponding Robot method; does not throw an exception
static Direction getDirection()
          wrapper for corresponding Robot method; does not throw an exception
static double getEnergonLevel()
          wrapper for corresponding Robot method; does not throw an exception
static Team getFlagTeam()
          Returns whether your robot is currently carrying a flag.
 Robot getGroundRobotAtLocation(MapLocation loc)
          Sense any Robots ON THE GROUND at this location.
static MapLocation getLocation()
          wrapper for corresponding GameObject method; does not throw an exception
 Message getNextMessage()
          Retrieve the next message waiting in your message queue.
static Robot getRobot()
          Use this method to access your robot
static int getRoundsUntilIdle()
          wrapper for corresponding Robot method; does not throw an exception
static Team getTeam()
          wrapper for corresponding GameObject method; does not throw an exception
 TerrainType getTerrainType(MapLocation loc)
          Sense the terrain type at a MapLocation.
static RobotType getType()
          wrapper for corresponding GameObject method; does not throw an exception
 int getUnitCount(RobotType type)
          Get the number of units of a certain RobotType on your team.
static boolean isActive()
          wrapper for corresponding Robot method; does not throw an exception
 boolean isMapShrinking()
          Return whether or not the map is in a state of overtime where it shrinks.
 void layMine(double amount)
          Create a new mine in front of you, and spend some of your energon on it.
 void moveBackward()
          Move one square backward.
 void moveForward()
          Move this robot forward one square in its current direction.
 void pickupFlag()
          Grab the flag in front of you.
abstract  void run()
          This is the main entry point into the player.
 MapLocation senseEnemyFlag()
          Returns the location of the enemy team's flag.
 Mine senseMineAhead()
          Get the Mine in the square in front of you, if you are carrying a flag.
 Robot[] senseNearbyAirRobots()
          Get an array of all Robots IN THE AIR in your current sensor range, excepting the calling robot.
 Robot[] senseNearbyGroundRobots()
          Get an array of all Robots ON THE GROUND in your current sensor range, excepting the calling robot.
 MapLocation senseTeamFlag()
          Get the location of your team flag.
 void setDirection(Direction newDirection)
          Set your robot's direction.
 void spawn(RobotType type)
          Create a new Robot in front of you.
 void transferEnergon(double amount)
          Transfer a specified amount of energon to the robot in front of you.
 void yield()
          Ends the current round and gives your robot a slight energon bonus (defined in robocraft.common.GameConstants.YIELD_ENERGON_BONUS).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractRobotPlayer

public AbstractRobotPlayer()
Method Detail

getRobot

public static Robot getRobot()
Use this method to access your robot


run

public abstract void run()
This is the main entry point into the player. Override this method to do all your work. You probably want a continuous loop in here, because if this method ever returns, then your robot will die.


isMapShrinking

public boolean isMapShrinking()
Return whether or not the map is in a state of overtime where it shrinks. Always succeeds.


getTerrainType

public TerrainType getTerrainType(MapLocation loc)
                           throws GameActionException
Sense the terrain type at a MapLocation.
  • Does not end the round.
  • Does not engage you in an action.
  • Returns:
    TerrainType representing terrain constant as described in TerrainType class.
    Throws:
    GameActionException - under any of the following circumstances:
  • You are not within sensor range of the given square.

  • senseNearbyGroundRobots

    public Robot[] senseNearbyGroundRobots()
    Get an array of all Robots ON THE GROUND in your current sensor range, excepting the calling robot. The order of the objects returned is undefined. If there are no other objects in your sensor range, a zero-length array is returned.
  • Does not end the round.
  • Does not engage you in an action.
  • Returns:
    array of Robot objects.

    senseNearbyAirRobots

    public Robot[] senseNearbyAirRobots()
    Get an array of all Robots IN THE AIR in your current sensor range, excepting the calling robot. The order of the objects returned is undefined. If there are no other objects in your sensor range, a zero-length array is returned.
  • Does not end the round.
  • Does not engage you in an action.
  • Returns:
    array of Robot objects.

    senseMineAhead

    public Mine senseMineAhead()
                        throws GameActionException
    Get the Mine in the square in front of you, if you are carrying a flag. If there is no mine in that square, returns null.
  • Does not end the round.
  • Does not engage you in an action.
  • Returns:
    Mine object, or null if no mine there.
    Throws:
    GameActionException - under any of the following circumstances:
  • You are not carrying a flag (either team).

  • getGroundRobotAtLocation

    public Robot getGroundRobotAtLocation(MapLocation loc)
                                   throws GameActionException
    Sense any Robots ON THE GROUND at this location.
  • Does not end the round.
  • Does not engage you in an action.
  • Parameters:
    loc - the location of the square you are sensing.
    Returns:
    Robot at this location ON THE GROUND, or null if there is none.
    Throws:
    GameActionException - under any of the following circumstances:
  • You are not within sensor range of loc.

  • getAirRobotAtLocation

    public Robot getAirRobotAtLocation(MapLocation loc)
                                throws GameActionException
    Sense any Robots IN THE AIR at this location.
  • Does not end the round.
  • Does not engage you in an action.
  • Parameters:
    loc - the location of the square you are sensing.
    Returns:
    Robot at this location IN THE AIR, or null if there is none.
    Throws:
    GameActionException - under any of the following circumstances:
  • You are not within sensor range of loc.

  • getFlagTeam

    public static Team getFlagTeam()
    Returns whether your robot is currently carrying a flag. If your robot is carrying no flags, it returns null. If your robot is carrying the flag for team A or B, it returns Team.A or Team.B, as appropriate. If your robot is carrying both flags, then the game is over and you cannot execute this method.


    senseTeamFlag

    public MapLocation senseTeamFlag()
    Get the location of your team flag. This ability is for all robots.
  • Does not end the round.
  • Does not engage you in an action.
  • Returns:
    MapLocation of team flag.

    senseEnemyFlag

    public MapLocation senseEnemyFlag()
    Returns the location of the enemy team's flag. If you are carrying a flag (either team), then this method will return a valid MapLocation. If you are not carrying a flag, but are within sensor range of the enemy flag, this method will also return its location. Otherwise, it returns null.
  • Does not end the round.
  • Does not engage you in an action.
  • Returns:
    MapLocation of enemy team flag, or null.

    getNextMessage

    public Message getNextMessage()
    Retrieve the next message waiting in your message queue.
  • Does not end the round.
  • Does not engage you in an action.
  • Returns:
    next Message object in your queue, or null if your queue is empty.

    getUnitCount

    public int getUnitCount(RobotType type)
    Get the number of units of a certain RobotType on your team.
  • Does not end the round.
  • Does not engage you in an action.
  • Returns:
    number of type units on your team.

    yield

    public void yield()
    Ends the current round and gives your robot a slight energon bonus (defined in robocraft.common.GameConstants.YIELD_ENERGON_BONUS). Never fails.


    setDirection

    public void setDirection(Direction newDirection)
                      throws GameActionException
    Set your robot's direction.

    Throws:
    GameActionException - if you are not currently idle, or if you pass a non-direction direction (i.e. OMNI OR NONE).

    pickupFlag

    public void pickupFlag()
                    throws GameActionException
    Grab the flag in front of you. This method requires that there is a flag directly in front of you.

    Throws:
    GameActionException - under any of the following conditions:
  • You are not idle.
  • There is no flag in front of you.
  • The flag is being carried by a robot.

  • depositFlag

    public void depositFlag()
                     throws GameActionException
    Deposit the flag you are carrying into the square in front of you.

    Throws:
    GameActionException - under any of the following conditions:
  • You are not idle.
  • You are not carrying a flag.
  • The square in front of you is a water square or is occupied by a robot, mine, or flag.

  • transferEnergon

    public void transferEnergon(double amount)
                         throws GameActionException
    Transfer a specified amount of energon to the robot in front of you. You may not transfer more energon than you currently have. Ground robots can only transfer to toher ground robots, and air robots to other air robots. If the transfer would put the receiving robot above its maxEnergon level, then its new energon level will be equals to the maxEnergon level, and the excess energon will be lost.
  • Ends the round.
  • Does not engage you in an action.
  • Parameters:
    amount - the amount of energon to transfer to the robot in front of you.
    Throws:
    GameActionException - under any of the following conditions:
  • You are not idle.
  • You do not have amount energon.
  • There is no robot in front of you

  • broadcastMessage

    public void broadcastMessage(Message msg)
    Broadcasts a message to all Robots currently in your broadcast range.

    This method will immediately add msg to the message queues of all robots in your broadcast range. It always succeeds.

    You are charged a small amount of energon for every message that you broadcast. The cost of sending a message is equal to (GameConstants.BROADCAST_FIXED_COST + GameConstants.BROADCAST_COST_PER_BYTE*sizeBytes) where sizeBytes is the size of the message, in bytes.

    Parameters:
    msg - the message you want to broadcast.

    moveForward

    public void moveForward()
                     throws GameActionException
    Move this robot forward one square in its current direction. After you move (if it succeeds), your new location will immediately change to the destination square, but you will be engaged in the ActionType.MOVING action for some number of rounds (defined in GameConstants, depending on the type of robot you are).

    Throws:
    GameActionException - under any of the following conditions:
  • You are not idle
  • The destination square is not empty
  • The destination terrain is not traversable by your unit

  • moveBackward

    public void moveBackward()
                      throws GameActionException
    Move one square backward. See moveForward().

    Throws:
    GameActionException

    attackGround

    public void attackGround(MapLocation targetLoc)
                      throws GameActionException
    Initiate an attack on the GROUND in a specified location. If there is a Robot on the GROUND in this location, it will feel some damage.
  • Ends the current round.
  • Engages you in action ActionType.ATTACKING
  • Parameters:
    targetLoc - the location of the square you are attacking.
    Throws:
    GameActionException - under any of the following circumstances:
  • You are not idle.
  • You are not within attack range of loc.
  • You cannot attack GROUND.

  • attackAir

    public void attackAir(MapLocation targetLoc)
                   throws GameActionException
    Initiate an attack on the AIR in a specified location. If there is a Robot in the AIR in this location, it will feel some damage.
  • Ends the current round.
  • Engages you in action ActionType.ATTACKING
  • Parameters:
    targetLoc - the location of the square you are attacking.
    Throws:
    GameActionException - under any of the following circumstances:
  • You are not idle.
  • You are not within attack range of loc.
  • You cannot attack AIR.

  • layMine

    public void layMine(double amount)
                 throws GameActionException
    Create a new mine in front of you, and spend some of your energon on it.

    Parameters:
    amount - the amount of energon to put into the new mine. Your energon supply will be decreased by this amount.
    Throws:
    GameActionException - under any of the following conditions:
  • You are not idle.
  • You are not a Sentry.
  • You do not have at least amount energon.
  • amount is within GameConstants.MIN_MINE_POWER and GameConstants.MAX_MINE_POWER
  • The location in front of you is not empty or accessable (i.e. you can't move forward)

  • spawn

    public void spawn(RobotType type)
               throws GameActionException
    Create a new Robot in front of you.

    This method requires that the square in front of you is empty and accessable (i.e. you COULD move forward according to canMove() IF you were the robot type you are spawning). You cannot cause yourself to have less than or equal to 0 energon by performing a spawn. The energon lost when spawning is the SPAWN_COST of the new robot.

    Ground units may only spawn other ground units, and air other air units.

    Parameters:
    type - the type of robot to spawn in the square directly in front of you.
    Throws:
    GameActionException - under any of the following conditions:
  • You are not idle.
  • You do not have enough energon for this robot type.
  • You could not move into the square in front of you, if you were a robot of type type.
  • You have exceeded the unit limit for this robot type
  • This unit is an air/ground unit and you are not the same.

  • getTeam

    public static Team getTeam()
    wrapper for corresponding GameObject method; does not throw an exception


    getType

    public static RobotType getType()
    wrapper for corresponding GameObject method; does not throw an exception


    getLocation

    public static MapLocation getLocation()
    wrapper for corresponding GameObject method; does not throw an exception


    getEnergonLevel

    public static double getEnergonLevel()
    wrapper for corresponding Robot method; does not throw an exception


    isActive

    public static boolean isActive()
    wrapper for corresponding Robot method; does not throw an exception


    getCurrentAction

    public static ActionType getCurrentAction()
    wrapper for corresponding Robot method; does not throw an exception


    getDirection

    public static Direction getDirection()
    wrapper for corresponding Robot method; does not throw an exception


    getRoundsUntilIdle

    public static int getRoundsUntilIdle()
    wrapper for corresponding Robot method; does not throw an exception


    getAttackPower

    public static double getAttackPower()
    wrapper for corresponding Robot method; does not throw an exception


    getBytecodesPerRound

    public static int getBytecodesPerRound()
    wrapper for corresponding Robot method; does not throw an exception


    canMove

    public static boolean canMove(Direction dir)
    wrapper for corresponding Robot method; does not throw an exception.


    canAttackAir

    public static boolean canAttackAir()
    wrapper for corresponding Robot method; does not throw an exception


    canAttackGround

    public static boolean canAttackGround()
    wrapper for corresponding Robot method; does not throw an exception


    canSenseSquare

    public static boolean canSenseSquare(MapLocation loc)
    wrapper for corresponding Robot method; does not throw an exception


    canSenseObject

    public static boolean canSenseObject(GameObject obj)
    wrapper for corresponding Robot method; does not throw an exception


    canAttackSquare

    public static boolean canAttackSquare(MapLocation loc)
    wrapper for corresponding Robot method that does not throw an exception