Interface RobotController


public interface RobotController
A RobotController allows contestants to make their robot sense and interact with the game world. When a contestant's RobotPlayer is constructed, it is passed an instance of RobotController that controls the newly created robot.
  • Method Details

    • getRoundNum

      int getRoundNum()
      Returns the current round number, where round 1 is the first round of the match.
      Returns:
      the current round number, where round 1 is the first round of the match
      Bytecode cost:
      1
    • getMapWidth

      int getMapWidth()
      Returns the width of the game map. Valid x coordinates range from 0 (inclusive) to the width (exclusive).
      Returns:
      the map width
      Bytecode cost:
      1
    • getMapHeight

      int getMapHeight()
      Returns the height of the game map. Valid y coordinates range from 0 (inclusive) to the height (exclusive).
      Returns:
      the map height
      Bytecode cost:
      1
    • getResourcePattern

      boolean[][] getResourcePattern()
      Returns the 5x5 resource pattern.
      Returns:
      a boolean array of arrays, where entry [i][j] is true if the i'th row and j'th column of the pattern should use the secondary color
      Bytecode cost:
      2
    • getTowerPattern

      boolean[][] getTowerPattern(UnitType type) throws GameActionException
      Returns the 5x5 pattern needed to be drawn to build a tower of the specified type.
      Parameters:
      type - the type of tower to build. Must be a tower type.
      Returns:
      a boolean array of arrays, where entry [i][j] is true if the i'th row and j'th column of the pattern should use the secondary color
      Throws:
      GameActionException
      Bytecode cost:
      2
    • getID

      int getID()
      Returns the ID of this robot.
      Returns:
      the ID of this robot
      Bytecode cost:
      1
    • getTeam

      Team getTeam()
      Returns this robot's Team.
      Returns:
      this robot's Team
      Bytecode cost:
      1
    • getLocation

      MapLocation getLocation()
      Returns this robot's current location.
      Returns:
      this robot's current location
      Bytecode cost:
      1
    • getHealth

      int getHealth()
      Returns this robot's current health.
      Returns:
      this robot's current health
      Bytecode cost:
      1
    • getPaint

      int getPaint()
      Returns this robot's current paint amount.
      Returns:
      this robot's current paint amount
      Bytecode cost:
      1
    • getMoney

      int getMoney()
      Returns the amount of money that this robot's team has.
      Returns:
      the amount of money this robot's team has
      Bytecode cost:
      1
    • getChips

      int getChips()
      Alias for getMoney
      Returns:
      the amount of money this robot's team has
      Bytecode cost:
      1
    • getType

      UnitType getType()
      Returns what UnitType this robot is.
      Returns:
      the UnitType of this robot
      Bytecode cost:
      1
    • getNumberTowers

      int getNumberTowers()
      Returns how many allied towers are currently alive.
      Returns:
      the number of alive allied towers.
      Bytecode cost:
      5
    • onTheMap

      boolean onTheMap(MapLocation loc)
      Checks whether a MapLocation is on the map.
      Parameters:
      loc - the location to check
      Returns:
      true if the location is on the map; false otherwise
      Bytecode cost:
      5
    • canSenseLocation

      boolean canSenseLocation(MapLocation loc)
      Checks whether the given location is within the robot's vision range, and if it is on the map.
      Parameters:
      loc - the location to check
      Returns:
      true if the given location is within the robot's vision range and is on the map; false otherwise
      Bytecode cost:
      5
    • isLocationOccupied

      boolean isLocationOccupied(MapLocation loc) throws GameActionException
      Checks whether a robot is at a given location. Assumes the location is valid.
      Parameters:
      loc - the location to check
      Returns:
      true if a robot is at the location
      Throws:
      GameActionException - if the location is not within vision range or on the map
      Bytecode cost:
      5
    • canSenseRobotAtLocation

      boolean canSenseRobotAtLocation(MapLocation loc)
      Checks whether a robot is at a given location. Assume the location is valid.
      Parameters:
      loc - the location to check
      Returns:
      true if a robot is at the location, false if there is no robot or the location can not be sensed
      Bytecode cost:
      5
    • senseRobotAtLocation

      RobotInfo senseRobotAtLocation(MapLocation loc) throws GameActionException
      Senses the robot at the given location, or null if there is no robot there.
      Parameters:
      loc - the location to check
      Returns:
      the robot at the given location
      Throws:
      GameActionException - if the location is not within vision range
      Bytecode cost:
      15
    • canSenseRobot

      boolean canSenseRobot(int id)
      Tests whether the given robot exists and if it is within this robot's vision range.
      Parameters:
      id - the ID of the robot to query
      Returns:
      true if the given robot is within this robot's vision range and exists; false otherwise
      Bytecode cost:
      5
    • senseRobot

      RobotInfo senseRobot(int id) throws GameActionException
      Senses information about a particular robot given its ID.
      Parameters:
      id - the ID of the robot to query
      Returns:
      a RobotInfo object for the sensed robot
      Throws:
      GameActionException - if the robot cannot be sensed (for example, if it doesn't exist or is out of vision range)
      Bytecode cost:
      25
    • senseNearbyRobots

      RobotInfo[] senseNearbyRobots()
      Returns all robots within vision radius. The objects are returned in no particular order.
      Returns:
      array of RobotInfo objects, which contain information about all the robots you saw
      Bytecode cost:
      100
    • senseNearbyRobots

      RobotInfo[] senseNearbyRobots(int radiusSquared) throws GameActionException
      Returns all robots that can be sensed within a certain distance of this robot. The objects are returned in no particular order.
      Parameters:
      radiusSquared - return robots this distance away from the center of this robot; if -1 is passed, all robots within vision radius are returned; if radiusSquared is larger than the robot's vision radius, the vision radius is used
      Returns:
      array of RobotInfo objects of all the robots you saw
      Throws:
      GameActionException - if the radius is negative (and not -1)
      Bytecode cost:
      100
    • senseNearbyRobots

      RobotInfo[] senseNearbyRobots(int radiusSquared, Team team) throws GameActionException
      Returns all robots of a given team that can be sensed within a certain distance of this robot. The objects are returned in no particular order.
      Parameters:
      radiusSquared - return robots this distance away from the center of this robot; if -1 is passed, all robots within vision radius are returned; if radiusSquared is larger than the robot's vision radius, the vision radius is used
      team - filter game objects by the given team; if null is passed, robots from any team are returned
      Returns:
      array of RobotInfo objects of all the robots you saw
      Throws:
      GameActionException - if the radius is negative (and not -1)
      Bytecode cost:
      100
    • senseNearbyRobots

      RobotInfo[] senseNearbyRobots(MapLocation center, int radiusSquared, Team team) throws GameActionException
      Returns all robots of a given team that can be sensed within a certain radius of a specified location. The objects are returned in no particular order.
      Parameters:
      center - center of the given search radius
      radiusSquared - return robots this distance away from the center of this robot; if -1 is passed, all robots within vision radius are returned; if radiusSquared is larger than the robot's vision radius, the vision radius is used
      team - filter game objects by the given team; if null is passed, objects from all teams are returned
      Returns:
      array of RobotInfo objects of the robots you saw
      Throws:
      GameActionException - if the radius is negative (and not -1) or the center given is null
      Bytecode cost:
      100
    • sensePassability

      boolean sensePassability(MapLocation loc) throws GameActionException
      Given a senseable location, returns whether that location is passable (a wall).
      Parameters:
      loc - the given location
      Returns:
      whether that location is passable
      Throws:
      GameActionException - if the robot cannot sense the given location
      Bytecode cost:
      5
    • senseMapInfo

      MapInfo senseMapInfo(MapLocation loc) throws GameActionException
      Senses the map info at a location. MapInfo includes walls, paint, marks, and ruins
      Parameters:
      loc - to sense map at
      Returns:
      MapInfo describing map at location
      Throws:
      GameActionException - if location can not be sensed
      Bytecode cost:
      5
    • senseNearbyMapInfos

      MapInfo[] senseNearbyMapInfos()
      Return map info for all senseable locations. MapInfo includes walls, paint, marks, and ruins.
      Returns:
      MapInfo about all locations within vision radius
      Bytecode cost:
      100
    • senseNearbyMapInfos

      MapInfo[] senseNearbyMapInfos(int radiusSquared) throws GameActionException
      Return map info for all senseable locations within a radius squared. If radiusSquared is larger than the robot's vision radius, uses the robot's vision radius instead. If -1 is passed, all locations within vision radius are returned. MapInfo includes walls, paint, marks, and ruins.
      Parameters:
      radiusSquared - the squared radius of all locations to be returned
      Returns:
      MapInfo about all locations within vision radius
      Throws:
      GameActionException - if the radius is negative (and not -1)
      Bytecode cost:
      100
    • senseNearbyMapInfos

      MapInfo[] senseNearbyMapInfos(MapLocation center) throws GameActionException
      Return map info for all senseable locations within vision radius of a center location. MapInfo includes walls, paint, marks, and ruins
      Parameters:
      center - the center of the search area
      Returns:
      MapInfo about all locations within vision radius
      Throws:
      GameActionException - if center is null
      Bytecode cost:
      100
    • senseNearbyMapInfos

      MapInfo[] senseNearbyMapInfos(MapLocation center, int radiusSquared) throws GameActionException
      Return map info for all senseable locations within a radius squared of a center location. If radiusSquared is larger than the robot's vision radius, uses the robot's vision radius instead. If -1 is passed, all locations within vision radius are returned. MapInfo includes walls, paint, marks, and ruins
      Parameters:
      center - the center of the search area
      radiusSquared - the squared radius of all locations to be returned
      Returns:
      MapInfo about all locations within vision radius
      Throws:
      GameActionException - if the radius is negative (and not -1)
      Bytecode cost:
      100
    • senseNearbyRuins

      MapLocation[] senseNearbyRuins(int radiusSquared) throws GameActionException
      Returns the location of all nearby ruins that are visible to the robot. If radiusSquared is greater than the robot's vision radius, uses the robot's vision radius instead.
      Parameters:
      radiusSquared - squared radius of all locations to be returned, -1 for max radius
      Returns:
      all locations containing ruins
      Throws:
      GameActionException - if a radius less than -1 is provided
      Bytecode cost:
      100
    • adjacentLocation

      MapLocation adjacentLocation(Direction dir)
      Returns the location adjacent to current location in the given direction.
      Parameters:
      dir - the given direction
      Returns:
      the location adjacent to current location in the given direction
      Bytecode cost:
      1
    • getAllLocationsWithinRadiusSquared

      MapLocation[] getAllLocationsWithinRadiusSquared(MapLocation center, int radiusSquared) throws GameActionException
      Returns a list of all locations within the given radiusSquared of a location. If radiusSquared is larger than the robot's vision radius, uses the robot's vision radius instead. Checks that radiusSquared is non-negative.
      Parameters:
      center - the given location
      radiusSquared - return locations within this distance away from center
      Returns:
      list of locations on the map and within radiusSquared of center
      Throws:
      GameActionException - if the radius is negative (and not -1)
      Bytecode cost:
      100
    • isActionReady

      boolean isActionReady()
      Tests whether the robot can act.
      Returns:
      true if the robot can act
      Bytecode cost:
      1
    • getActionCooldownTurns

      int getActionCooldownTurns()
      Returns the number of action cooldown turns remaining before this unit can act again. When this number is strictly less than GameConstants.COOLDOWN_LIMIT, isActionReady() is true and the robot can act again. This number decreases by GameConstants.COOLDOWNS_PER_TURN every turn.
      Returns:
      the number of action turns remaining before this unit can act again
      Bytecode cost:
      1
    • isMovementReady

      boolean isMovementReady()
      Tests whether the robot can move.
      Returns:
      true if the robot can move
      Bytecode cost:
      1
    • getMovementCooldownTurns

      int getMovementCooldownTurns()
      Returns the number of movement cooldown turns remaining before this unit can move again. When this number is strictly less than GameConstants.COOLDOWN_LIMIT, isMovementReady() is true and the robot can move again. This number decreases by GameConstants.COOLDOWNS_PER_TURN every turn.
      Returns:
      the number of cooldown turns remaining before this unit can move again
      Bytecode cost:
      1
    • canMove

      boolean canMove(Direction dir)
      Checks whether this robot can move one step in the given direction. Returns false if the robot is not in a mode that can move, if the target location is not on the map, if the target location is occupied, if the target location is impassible, or if there are cooldown turns remaining.
      Parameters:
      dir - the direction to move in
      Returns:
      true if it is possible to call move without an exception
      Bytecode cost:
      10
    • move

      void move(Direction dir) throws GameActionException
      Moves one step in the given direction.
      Parameters:
      dir - the direction to move in
      Throws:
      GameActionException - if the robot cannot move one step in this direction, such as cooldown being too high, the target location being off the map, or the target destination being occupied by another robot, or the target destination being impassible.
      Bytecode cost:
      0
    • canBuildRobot

      boolean canBuildRobot(UnitType type, MapLocation loc)
      Checks if a tower can spawn a robot at the given location. Robots can spawn within a circle of radius of sqrt(4) of the tower.
      Parameters:
      type - the type of robot to spawn
      loc - the location to spawn the robot at
      Returns:
      true if robot can be built at loc
      Bytecode cost:
      10
    • buildRobot

      void buildRobot(UnitType type, MapLocation loc) throws GameActionException
      Spawns a robot at the given location. Robots can spawn within a circle of radius of sqrt(4) of the tower.
      Parameters:
      type - the type of robot to spawn
      loc - the location to spawn the robot at
      Throws:
      GameActionException
      Bytecode cost:
      20
    • canMark

      boolean canMark(MapLocation loc)
      Checks if the location can be marked.
      Parameters:
      loc - the location to mark
      Bytecode cost:
      5
    • mark

      void mark(MapLocation loc, boolean secondary) throws GameActionException
      Adds a mark at the given location.
      Parameters:
      loc - the location to mark
      secondary - whether the secondary color should be used
      Throws:
      GameActionException
      Bytecode cost:
      5
    • canRemoveMark

      boolean canRemoveMark(MapLocation loc)
      Checks if a mark at the location can be removed.
      Parameters:
      loc - the location that has the mark
      Bytecode cost:
      5
    • removeMark

      void removeMark(MapLocation loc) throws GameActionException
      Removes the mark at the given location.
      Parameters:
      loc - the location that has the mark
      Throws:
      GameActionException
      Bytecode cost:
      5
    • canMarkTowerPattern

      boolean canMarkTowerPattern(UnitType type, MapLocation loc)
      Checks if the robot can build a tower by marking a 5x5 pattern centered at the given location. This requires there to be a ruin at the location.
      Parameters:
      type - which tower pattern type should be used
      loc - the center of the 5x5 pattern
      Returns:
      true if a tower pattern can be marked at loc
      Bytecode cost:
      50
    • markTowerPattern

      void markTowerPattern(UnitType type, MapLocation loc) throws GameActionException
      Builds a tower by marking a 5x5 pattern centered at the given location. This requires there to be a ruin at the location.
      Parameters:
      type - the type of tower to mark the pattern for
      loc - the center of the 5x5 pattern
      Throws:
      GameActionException
      Bytecode cost:
      50
    • canUpgradeTower

      boolean canUpgradeTower(MapLocation loc)
      Checks if a tower can be upgraded by verifying conditions on the location, team, tower level, and cost.
      Parameters:
      loc - the location to upgrade the tower at
      Bytecode cost:
      2
    • upgradeTower

      void upgradeTower(MapLocation loc) throws GameActionException
      Upgrades a tower if possible; subtracts the corresponding amount of money from the team.
      Parameters:
      loc - the location to upgrade the tower at
      Throws:
      GameActionException
      Bytecode cost:
      0
    • canMarkResourcePattern

      boolean canMarkResourcePattern(MapLocation loc)
      Checks if the robot can mark a 5x5 special resource pattern centered at the given location.
      Parameters:
      loc - the center of the resource pattern
      Returns:
      true if an SRP can be marked at loc
      Bytecode cost:
      50
    • markResourcePattern

      void markResourcePattern(MapLocation loc) throws GameActionException
      Marks a 5x5 special resource pattern centered at the given location.
      Parameters:
      loc - the center of the resource pattern
      Throws:
      GameActionException
      Bytecode cost:
      50
    • canCompleteTowerPattern

      boolean canCompleteTowerPattern(UnitType type, MapLocation loc)
      Checks if the robot can build a tower at the given location. This requires there to be a ruin at the location. This also requires the 5x5 region to be painted correctly.
      Parameters:
      type - the type of tower to build
      loc - the location to build at
      Returns:
      true if tower can be built at loc
      Bytecode cost:
      50
    • completeTowerPattern

      void completeTowerPattern(UnitType type, MapLocation loc) throws GameActionException
      Builds a tower at the given location. This requires there to be a ruin at the location. This also requires the 5x5 region to be painted correctly.
      Parameters:
      type - the type of tower to build
      loc - the location to build at
      Throws:
      GameActionException
      Bytecode cost:
      50
    • canCompleteResourcePattern

      boolean canCompleteResourcePattern(MapLocation loc)
      Checks if the robot can complete a 5x5 special resource pattern centered at the given location. This requires the 5x5 region to be painted correctly.
      Parameters:
      loc - the center of the resource pattern
      Returns:
      true if the SRP can be completed at loc
      Bytecode cost:
      50
    • completeResourcePattern

      void completeResourcePattern(MapLocation loc) throws GameActionException
      Completes a 5x5 special resource pattern centered at the given location. This requires the 5x5 region to be painted correctly.
      Parameters:
      loc - the center of the resource pattern
      Throws:
      GameActionException
      Bytecode cost:
      50
    • canPaint

      boolean canPaint(MapLocation loc)
      Tests whether this robot can paint the given location.
      Parameters:
      loc - target location to paint
      Returns:
      true if rc.attack(loc) will paint the given location
      Bytecode cost:
      10
    • canAttack

      boolean canAttack(MapLocation loc)
      Tests whether this robot can attack the given location. Types of attacks for specific units determine whether or not towers, other robots, or empty tiles can be attacked.
      Parameters:
      loc - target location to attack
      Returns:
      whether it is possible to attack the given location
      Bytecode cost:
      10
    • attack

      void attack(MapLocation loc, boolean useSecondaryColor) throws GameActionException
      Performs the specific attack for this robot type.
      Parameters:
      loc - the target location to attack (for splashers, the center location) Note: for a tower, leaving loc null represents an area attack
      useSecondaryColor - whether or not the attack should use a secondary color
      Throws:
      GameActionException - if conditions for attacking are not satisfied
      Bytecode cost:
      0
    • attack

      void attack(MapLocation loc) throws GameActionException
      Performs the specific attack for this robot type, defaulting to the primary color
      Parameters:
      loc - the target location to attack (for splashers, the center location) Note: for a tower, leaving loc null represents an area attack
      Throws:
      GameActionException - if conditions for attacking are not satisfied
      Bytecode cost:
      0
    • canMopSwing

      boolean canMopSwing(Direction dir)
      Tests whether this robot (which must be a mopper) can perform a mop swing in a specific direction
      Parameters:
      dir - the direction in which to mop swing
      Returns:
      whether it is possible to mop swing in the given direction
      Bytecode cost:
      10
    • mopSwing

      void mopSwing(Direction dir) throws GameActionException
      Performs a mop swing in the given direction (only for moppers!)
      Parameters:
      dir - the direction in which to mop swing
      Throws:
      GameActionException - if conditions for attacking are not satisfied
      Bytecode cost:
      0
    • canSendMessage

      boolean canSendMessage(MapLocation loc)
      Returns true if the unit can send a message to a specific location, false otherwise. We can send a message to a location if it is within a specific distance and connected by paint, and only if one unit is a robot and the other is a tower.
      Parameters:
      loc - the location to send the message to
      Bytecode cost:
      50
    • canSendMessage

      boolean canSendMessage(MapLocation loc, int messageContent)
      Returns true if the unit can send a message to a specific location, false otherwise. We can send a message to a location if it is within a specific distance and connected by paint, and only if one unit is a robot and the other is a tower.
      Parameters:
      loc - the location to send the message to
      messageContent - the contents of the message. Does not affect whether or not the message can be sent.
      Bytecode cost:
      50
    • sendMessage

      void sendMessage(MapLocation loc, int messageContent) throws GameActionException
      Sends a message (contained in an int, so 4 bytes) to a specific unit at a location on the map, if it is possible
      Parameters:
      loc - the location to send the message to
      messageContent - an int representing the content of the message (up to 4 bytes)
      Throws:
      GameActionException - if conditions for messaging are not satisfied
      Bytecode cost:
      50
    • canBroadcastMessage

      boolean canBroadcastMessage()
      Returns true if this tower can broadcast a message. You can broadcast a message if this robot is a tower and the tower has not yet sent the maximum number of messages this round (broadcasting a message to other towers counts as one message sent, even if multiple towers receive the message).
      Returns:
      Whether this robot can broadcast a message
    • broadcastMessage

      void broadcastMessage(int messageContent) throws GameActionException
      Broadcasts a message to all friendly towers within the broadcasting radius. This works the same as sendMessage, but it can only be performed by towers and sends the message to all friendly towers within range simultaneously. The towers need not be connected by paint to receive the message.
      Parameters:
      messageContent - The message to broadcast.
      Throws:
      GameActionException - If the message can't be sent
    • readMessages

      Message[] readMessages(int roundNum)
      Reads all messages sent to this unit within the past 5 rounds if roundNum = -1, or only messages sent from the specified round otherwise
      Parameters:
      roundNum - the round number to read messages from, or -1 to read all messages in the queue
      Returns:
      All messages of the specified round, or all messages from the past 5 round.
      Bytecode cost:
      10
    • canTransferPaint

      boolean canTransferPaint(MapLocation loc, int amount)
      Tests whether you can transfer paint to a given robot/tower. You can give paint to an allied robot/tower if you are a mopper and can act at the given location. You can take paint from allied towers regardless of type, if you can act at the location. Pass in a negative number to take paint.
      Parameters:
      loc - the location of the robot/tower to transfer paint to
      amount - the amount of paint to transfer. Positive to give paint, negative to take paint.
      Returns:
      true if the robot can transfer paint to a robot/tower at the given location
    • transferPaint

      void transferPaint(MapLocation loc, int amount) throws GameActionException
      Transfers paint from the robot's stash to the stash of the allied robot or tower at loc. Pass in a negative number to take paint, positive to give paint.
      Parameters:
      loc - the location of the robot/tower to transfer paint to
      amount - the amount of paint to transfer. Positive to give paint, negative to take paint.
      Throws:
      GameActionException - if the robot is not able to transfer paint to the location
    • disintegrate

      void disintegrate()
      Destroys the robot.
      Bytecode cost:
      0
    • resign

      void resign()
      Causes your team to lose the game. It's like typing "gg."
      Bytecode cost:
      0
    • setIndicatorString

      void setIndicatorString(String string)
      Sets the indicator string for this robot for debugging purposes. Only the first GameConstants.INDICATOR_STRING_MAX_LENGTH characters are used.
      Parameters:
      string - the indicator string this round
      Bytecode cost:
      0
    • setIndicatorDot

      void setIndicatorDot(MapLocation loc, int red, int green, int blue) throws GameActionException
      Draw a dot on the game map for debugging purposes.
      Parameters:
      loc - the location to draw the dot
      red - the red component of the dot's color
      green - the green component of the dot's color
      blue - the blue component of the dot's color
      Throws:
      GameActionException - if the location is off the map
      Bytecode cost:
      0
    • setIndicatorLine

      void setIndicatorLine(MapLocation startLoc, MapLocation endLoc, int red, int green, int blue) throws GameActionException
      Draw a line on the game map for debugging purposes.
      Parameters:
      startLoc - the location to draw the line from
      endLoc - the location to draw the line to
      red - the red component of the line's color
      green - the green component of the line's color
      blue - the blue component of the line's color
      Throws:
      GameActionException - if any location is off the map
      Bytecode cost:
      0
    • setTimelineMarker

      void setTimelineMarker(String label, int red, int green, int blue)
      Adds a marker to the timeline at the current round for debugging purposes. Only the first GameConstants.TIMELINE_LABEL_MAX_LENGTH characters are used.
      Parameters:
      label - the label for the timeline marker
      red - the red component of the marker's color
      green - the green component of the marker's color
      blue - the blue component of the marker's color
      Bytecode cost:
      0