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, FLYER_ATTACK_POWER, FLYER_BROADCAST_RADIUS, FLYER_BYTECODES_PER_ROUND, FLYER_MAX_ENERGON, FLYER_ROUNDS_PER_ATTACK, FLYER_ROUNDS_PER_MOVE, FLYER_ROUNDS_PER_SPAWN, FLYER_ROUNDS_PER_WAKE, FLYER_SENSOR_RADIUS, FLYER_START_ENERGON, QUEEN_ATTACK_POWER, QUEEN_BROADCAST_RADIUS, QUEEN_BYTECODES_PER_ROUND, QUEEN_MAX_ENERGON, QUEEN_ROUNDS_PER_ATTACK, QUEEN_ROUNDS_PER_MOVE, QUEEN_ROUNDS_PER_SPAWN, QUEEN_ROUNDS_PER_WAKE, QUEEN_SENSOR_RADIUS, QUEEN_START_ENERGON, SHOOTER_ATTACK_DISTANCE, SHOOTER_ATTACK_POWER, SHOOTER_ATTACK_RANGE, SHOOTER_BROADCAST_RADIUS, SHOOTER_BYTECODES_PER_ROUND, SHOOTER_MAX_ENERGON, SHOOTER_ROUNDS_PER_ATTACK, SHOOTER_ROUNDS_PER_MOVE, SHOOTER_ROUNDS_PER_SPAWN, SHOOTER_ROUNDS_PER_WAKE, SHOOTER_SENSOR_DISTANCE, SHOOTER_SENSOR_RANGE, SHOOTER_START_ENERGON, SOLDIER_ATTACK_POWER, SOLDIER_BROADCAST_RADIUS, SOLDIER_BYTECODES_PER_ROUND, SOLDIER_MAX_ENERGON, SOLDIER_ROUNDS_PER_ATTACK, SOLDIER_ROUNDS_PER_MOVE, SOLDIER_ROUNDS_PER_SPAWN, SOLDIER_ROUNDS_PER_WAKE, SOLDIER_SENSOR_DISTANCE, SOLDIER_SENSOR_RANGE, SOLDIER_START_ENERGON, SPAWN_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 depositEnergon(int amount)
          Create a new energon cube in front of you, and deposit some of your energon into it.
 GameObject getAirObjectAtLocation(MapLocation loc)
          Sense any GameObjects 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
 GameObject getGroundObjectAtLocation(MapLocation loc)
          Sense any GameObjects 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 ObjectType getType()
          wrapper for corresponding GameObject method; does not throw an exception
static boolean isActive()
          wrapper for corresponding Robot method; does not throw an exception
 void moveBackward()
          Move one square backward.
 void moveForward()
          Move this robot forward one square in its current direction.
 void pickupEnergon()
          Grab some energon from the EnergonCube in front of you.
abstract  void run()
          This is the main entry point into the player.
 MapLocation senseEnemyQueen()
          Special ability for queens to get the location of the enemy queen.
 GameObject[] senseNearbyObjects()
          Get an array of all GameObjects in your current sensor range, excepting the calling robot.
 void setDirection(Direction newDirection)
          Set your robot's direction.
 void spawn(ObjectType type)
          Create a new 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.


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.

  • senseNearbyObjects

    public GameObject[] senseNearbyObjects()
    Get an array of all GameObjects 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 GameObjects. Each object in this array will either be an instance of Robot or EnergonCube.

    senseEnemyQueen

    public MapLocation senseEnemyQueen()
                                throws GameActionException
    Special ability for queens to get the location of the enemy queen.
  • Does not end the round.
  • Does not engage you in an action.
  • Returns:
    MapLocation of enemy queen.
    Throws:
    GameActionException - under any of the following conditions:
  • The enemy queen is dead
  • You are not of type QUEEN_ROBOT

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

    getGroundObjectAtLocation

    public GameObject getGroundObjectAtLocation(MapLocation loc)
                                         throws GameActionException
    Sense any GameObjects 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:
    GameObject 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.

  • getAirObjectAtLocation

    public GameObject getAirObjectAtLocation(MapLocation loc)
                                      throws GameActionException
    Sense any GameObjects 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:
    GameObject 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.

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

    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
  • The current direction is diagonal and a move would pass through untraversable squares

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

  • pickupEnergon

    public void pickupEnergon()
                       throws GameActionException
    Grab some energon from the EnergonCube in front of you. This method requires that there is an energon cube directly in front of you. If there is more energon in the cube in front of you than you can carry, then you will take as much as you can from the cube, which will continue to exist, only with that much less energon in it. If you take all the energon from the cube in front of you, the cube will disappear from the map.

    Throws:
    GameActionException - under any of the following conditions:
  • You are not idle.
  • There is no energon cube in front of you.

  • depositEnergon

    public void depositEnergon(int amount)
                        throws GameActionException
    Create a new energon cube in front of you, and deposit some of your energon into it.

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

  • spawn

    public void spawn(ObjectType 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). It does not require that you have enough energon to spawn the given robot type. The energon lost when spawning a Robot is half the MAX_ENERGON that robot can carry.

    Note that QueenRobots can spawn any type of robot, and all other robots can only spawn robots of the same type. (Flyers can spawn Flyers, etc.).

    Also, no robot can spawn a QueenRobot or an EnergonCube.

    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 could not move into the square in front of you, if you were a robot of type type.
  • You are trying to spawn a QueenRobot
  • You are trying to spawn an EnergonCube
  • You are not a queen, and you are trying to spawn a robot type different from your own.

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

    getTeam

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


    getType

    public static ObjectType 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