cz.cuni.amis.pogamut.defcon.agent.module.sensor
Class GameInfo

Package class diagram package GameInfo
java.lang.Object
  extended by cz.cuni.amis.pogamut.defcon.agent.module.sensor.GameInfo

public class GameInfo
extends Object

This class implements functionality that is not present within standard worldview, but it is important since it provides crucial information about the games' state.

Author:
Radek 'Black_Hand' Pibil

Nested Class Summary
 class GameInfo.LocationPair
           
 
Constructor Summary
GameInfo()
          Instantiates and prepares GameInfo for operation.
 
Method Summary
 boolean canCreateFleet(UnitType[] ships)
          Checks whether are there enough units of each type to create a fleet of a given composition.
 boolean debugIsReplayingGame()
          True if the game is currently replayed (Timeline has been clicked).
 int[] getActionQueue(int unitId)
          Array of unitIds of currently queued actions, for example nukes in a silo or planes on a carrier
 LinkedList<Location> getAIPlacementPoints()
          Returns current set of AI placement points.
 LinkedList<Integer> getAllEnemyTerritories()
          Returns a flat list of territories possessed by enemies.
 int getAllianceId(int teamId)
          Id of alliance.
 SortedMap<Integer,LinkedList<Integer>> getAlliancesWithTeamIds()
          List of Alliances Team Ids in the game.
 double getBomberRange()
          Returns range of a bomber.
 DefConLocation getCitiesGravityCenter(int teamId)
          Returns center of gravity of given enemy's cities.
 int[] getCityIds()
          Gets a list of cities.
 DefConLocation getCityLocation(int cityId)
          Returns location of the given city.
 GameInfo.LocationPair getClosestSailDistance(List<Location> borderA, List<Location> borderB)
          Finds a closest point on given border to a given point.
 cz.cuni.amis.pogamut.defcon.agent.module.sensor.GameInfo.LocationWithDistance getClosestSailTarget(Location location, List<Location> border)
          Finds a closest point on given border to a given point.
 int getCollateralDamage(int teamId)
          Sum of collateral damage deaths (deaths in own population) of the given team.
 int getDefconLevel()
          Current Defcon Stage, game starts with 5
 int getDesiredGameSpeed(int teamId)
          Currently requested game speed of given team.
 SortedMap<Integer,List<Integer>> getEnemiesCityIds()
          List of Enemies city Ids in the game.
 List<Integer> getEnemyCityIds()
          List of Enemies city Ids in the game.
 List<Integer> getEnemyCityIds(int enemyId)
          List of Enemy city Ids in the game.
 int getEnemyKills(int teamId)
          Sum of enemy kills of the given team (for scoring).
 int[] getEnemyTeamIds()
          List of Enemy Team Ids in the game.
 LinkedList<IDefConBasicEvent> getEvents()
          Updates all flags, which in turn generates events, which are then returned in a form of LinkedList.
 double getFighterRange()
          Returns range of a fighter.
 double getFleetDiameter(int fleetSize)
          Gets the smallest circle diameter, which could contain the whole fleet.
 int getFleetId(int unitId)
          Id of fleet of given unit.
 Location getFleetMemberOffset(int memberCount, int memberId)
          Offset of ship number memberId from center of fleet, given fleet has memberCount ships
 int[] getFleetMembers(int fleetId)
          Ids of ships in given fleet.
 int[] getFleets(int teamId)
          Fleet ids of given team.
 int getFriendlyDeaths(int teamId)
          Sum of friendly deaths (deaths in allied populations) of the given team.
 GameSpeed getGameSpeed()
          Current speed-up factor of the game over the real time passed.
 int getGameTick()
          Amount of update cycles (ticks) passed since game start
 float getGameTime()
          Current Game Time, measured in seconds.
 int getNukeSupply(int unitId)
          Returns amount of nukes present in the given unit.
 Location getObjectLocation(int objectId)
          Returns a location of the given object.
 int getOptionValue(String name)
          Value of certain option.
 int[] getOwnFleets()
          Own fleet ids.
 int getOwnTeamId()
          Own team id.
 int[] getOwnTeamTerritories()
          Territory Ids of territories that the team the player is in owns.
 double getRadarRange()
          Returns range of a single radar.
 float getRange(int unitId)
          Remaining range of unit.
 int getRemainingUnits(UnitType typeId)
          Amount of remaining units of given type that can be placed.
 boolean getRunning()
          Queries gameRunning flag.
 float getSailDistance(double locationA_x, double locationA_y, double locationB_x, double locationB_y)
          Distance in game between given coordinates on sea (performs pathfinding).
 float getSailDistance(float locationA_x, float locationA_y, float locationB_x, float locationB_y)
          Distance in game between given coordinates on sea (performs pathfinding).
 float getSailDistance(Location locationA, Location locationB)
          Distance in game between given coordinates on sea (performs pathfinding).
 double getSiloRange()
          Returns range of AA mode of a silo.
 int getStateCount(int unitId, int stateId)
          Returns number of activations of this state for this unit.
 int getStateCount(int unitId, IState state)
          Returns number of activations of this state for this unit.
 float getStateTimer(int unitId)
          Time until current state is active.
 double getSubNukeRange()
          Returns range of submarine nukes (SRBM).
 LinkedList<Location> getTargetCoords()
          Returns current set of AI target points.
 int getTeamId(int id)
          Team Id of given unit.
 int[] getTeamIds()
          List of Team Ids in the game.
 String getTeamName(int teamId)
          Name of the given team.
 int[] getTeamTerritories(int teamId)
          Territory Ids of territories that the given team owns.
 int getTeamTerritoriesCount(int teamId)
          Number of territories for given team, usually 1.
 int getTerritoriesCount()
          Returns the number of territories.
 int getTerritoryId(double longitude, double latitude)
          Territory Id of territory at given coordinates.
 int getTerritoryId(float longitude, float latitude)
          Territory Id of territory at given coordinates.
 int getTerritoryId(Location location)
          Get id of a land territory at a given location.
 int getTerritoryOwner(double longitude, double latitude)
          Returns the owner of a land territory, which contains given location or -1 if noone owns it.
 int getTerritoryOwner(int territoryId)
          Returns the owner of a territory with a given Id.
 int getTerritoryOwner(Location center)
          Returns the owner of a land territory, which contains given location or -1 if noone owns it.
 int[] getTerritoryOwners()
          Returns the territory to owner mapping array.
 UnitType getType(int unitId)
          Returns type of unit with this id.
 int getUnitCredits()
          Credits available for placement (if in variable unit mode).
 int getUnitValue(UnitType typeId)
          Value of given unit type (if in variable unit mode).
 Location getVelocity(int unitId)
          Movement direction of given unit, in longitude and latitude parts.
 float getVictoryTimer()
          Time remaining in game, if victory timer was started.
 boolean isBorder(float longitude, float latitude)
          True if given coordinates are on the border.
 boolean isCeaseFire(int teamId1, int teamId2)
          True iff the first team is in cease fire mode with the second team.
 boolean isRetaliating(int unitId)
          True iff given unit is automatically retaliating an earlier attack.
 boolean isSharingRadar(int teamId1, int teamId2)
          True iff the first team is sharing its radar with the second team.
 boolean isValidBuildingPlacementLocation(double longitude, double latitude)
          True iff given location is valid for building placement.
 boolean isValidBuildingPlacementLocation(Location location)
          True iff given location is valid for building placement.
 boolean isValidFleetPlacement(Location placement, int fleetSize)
          Simplifies queries for possibility of placing a fleet.
 boolean isValidFleetPlacementLocation(float longitude, float latitude, int fleetSize)
           
 boolean isValidPlacementLocation(double longitude, double latitude, UnitType typeId)
          True iff given location is valid for placement of given type.
 boolean isValidPlacementLocation(float longitude, float latitude, UnitType typeId)
          True iff given location is valid for placement of given type.
 boolean isValidShipPlacementLocation(double longitude, double latitude)
          True iff given location is valid for ship placement.
 boolean isValidShipPlacementLocation(Location location)
          True iff given location is valid for ship placement.
 boolean isValidStructureLocation(Location placement)
          Checks validity of placement for structures.
 boolean isValidTerritory(int teamId, double longitude, double latitude, boolean seaArea)
          True if the given coordinates belong to the given Team.
 boolean isValidTerritory(int teamId, float longitude, float latitude, boolean seaArea)
          True if the given coordinates belong to the given Team.
 boolean isValidTerritory(int teamId, Location location, boolean seaArea)
          True if the given coordinates belong to the given Team.
 boolean isVictoryTimerActive()
          True iff the victory-timer has been started
 boolean isVisible(int unitId, int byTeamId)
          True iff given unit is visible to given team.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GameInfo

public GameInfo()
Instantiates and prepares GameInfo for operation.

Method Detail

getEvents

public LinkedList<IDefConBasicEvent> getEvents()
Updates all flags, which in turn generates events, which are then returned in a form of LinkedList. This method is periodically called by DefconMessageProdducer.populateQueue().

Returns:
LinkedList of acquired events.

getAIPlacementPoints

public final LinkedList<Location> getAIPlacementPoints()
Returns current set of AI placement points.

Returns:
LinkedList of Locations

getTargetCoords

public final LinkedList<Location> getTargetCoords()
Returns current set of AI target points.

Returns:
LinkedList of Locations

getDefconLevel

public int getDefconLevel()
Current Defcon Stage, game starts with 5

Returns:
int Defcon stage

getGameTime

public float getGameTime()
Current Game Time, measured in seconds. Each tick, the game progresses by 0.1 sec * GameSpeed

Returns:
game time

getGameTick

public int getGameTick()
Amount of update cycles (ticks) passed since game start

Returns:
number of game ticks

getGameSpeed

public GameSpeed getGameSpeed()
Current speed-up factor of the game over the real time passed. Usually has values from 0 (paused), 1 (real time), 5, 10, 20, see enum GAMESPEED (GameSpeed class)

Returns:

getVictoryTimer

public float getVictoryTimer()
Time remaining in game, if victory timer was started. Test this with IsVictoryTimerStarted

Returns:

isVictoryTimerActive

public boolean isVictoryTimerActive()
True iff the victory-timer has been started

Returns:

getOptionValue

public int getOptionValue(String name)
Value of certain option.

Black_Hand: no idea what it does, might be related to the game settings (advanced options in game hosting) like CityPopulations. Expected to be called like: getOptionValue("CityPopulations").

Parameters:
name -
Returns:

debugIsReplayingGame

public boolean debugIsReplayingGame()
True if the game is currently replayed (Timeline has been clicked). TODO: e.g. game has been paused?

Returns:

getTeamId

public int getTeamId(int id)
Team Id of given unit.

Parameters:
id -
Returns:

getOwnFleets

public int[] getOwnFleets()
Own fleet ids.

Returns:

getFleets

public int[] getFleets(int teamId)
Fleet ids of given team. Only fleets ids with visible members are returned.

Parameters:
teamId -
Returns:

getFleetMembers

public int[] getFleetMembers(int fleetId)
Ids of ships in given fleet.

Parameters:
fleetId -
Returns:

getFleetId

public int getFleetId(int unitId)
Id of fleet of given unit.

Parameters:
unitId -
Returns:

getStateTimer

public float getStateTimer(int unitId)
Time until current state is active.

Parameters:
unitId -
Returns:

getActionQueue

public int[] getActionQueue(int unitId)
Array of unitIds of currently queued actions, for example nukes in a silo or planes on a carrier

Parameters:
unitId -
Returns:

isRetaliating

public boolean isRetaliating(int unitId)
True iff given unit is automatically retaliating an earlier attack.

Parameters:
unitId -
Returns:

isVisible

public boolean isVisible(int unitId,
                         int byTeamId)
True iff given unit is visible to given team. In full information mode, visibility information about other teams is available. In limited information mode, only visible units are accessible.

Parameters:
unitId -
byTeamId -
Returns:

getVelocity

public Location getVelocity(int unitId)
Movement direction of given unit, in longitude and latitude parts. The vector has the length of the unit speed (see also SPEED_*).

Parameters:
unitId -
Returns:

getRange

public float getRange(int unitId)
Remaining range of unit. If unlimited, -1 is returned.

Parameters:
unitId -
Returns:

getRemainingUnits

public int getRemainingUnits(UnitType typeId)
Amount of remaining units of given type that can be placed.

Parameters:
typeId -
Returns:

isValidPlacementLocation

public boolean isValidPlacementLocation(float longitude,
                                        float latitude,
                                        UnitType typeId)
True iff given location is valid for placement of given type. For fleets use getFleetMemberOffset to get offset from fleet center.

Parameters:
longitude -
latitude -
typeId -
Returns:

isValidPlacementLocation

public boolean isValidPlacementLocation(double longitude,
                                        double latitude,
                                        UnitType typeId)
True iff given location is valid for placement of given type. For fleets use getFleetMemberOffset to get offset from fleet center.

Parameters:
longitude -
latitude -
typeId -
Returns:

isValidShipPlacementLocation

public boolean isValidShipPlacementLocation(Location location)
True iff given location is valid for ship placement. For fleets use getFleetMemberOffset to get offset from fleet center.

Parameters:
longitude -
latitude -
Returns:

isValidShipPlacementLocation

public boolean isValidShipPlacementLocation(double longitude,
                                            double latitude)
True iff given location is valid for ship placement. For fleets use getFleetMemberOffset to get offset from fleet center.

Parameters:
longitude -
latitude -
Returns:

isValidBuildingPlacementLocation

public boolean isValidBuildingPlacementLocation(Location location)
True iff given location is valid for building placement. For fleets use getFleetMemberOffset to get offset from fleet center.

Parameters:
location -
Returns:

isValidBuildingPlacementLocation

public boolean isValidBuildingPlacementLocation(double longitude,
                                                double latitude)
True iff given location is valid for building placement. For fleets use getFleetMemberOffset to get offset from fleet center.

Parameters:
longitude -
latitude -
Returns:

isValidFleetPlacementLocation

public boolean isValidFleetPlacementLocation(float longitude,
                                             float latitude,
                                             int fleetSize)

getUnitCredits

public int getUnitCredits()
Credits available for placement (if in variable unit mode).

Returns:

getUnitValue

public int getUnitValue(UnitType typeId)
Value of given unit type (if in variable unit mode).

Parameters:
typeId -
Returns:

getSailDistance

public float getSailDistance(Location locationA,
                             Location locationB)
Distance in game between given coordinates on sea (performs pathfinding).

Parameters:
locationA -
locationB -
Returns:
distance

getSailDistance

public float getSailDistance(double locationA_x,
                             double locationA_y,
                             double locationB_x,
                             double locationB_y)
Distance in game between given coordinates on sea (performs pathfinding).

Parameters:
locationA -
locationB -
Returns:
distance

getSailDistance

public float getSailDistance(float locationA_x,
                             float locationA_y,
                             float locationB_x,
                             float locationB_y)
Distance in game between given coordinates on sea (performs pathfinding).

Parameters:
locationA_x -
locationB_x -
Returns:
distance

getClosestSailTarget

public cz.cuni.amis.pogamut.defcon.agent.module.sensor.GameInfo.LocationWithDistance getClosestSailTarget(Location location,
                                                                                                          List<Location> border)
Finds a closest point on given border to a given point. VERY ROUGH!!! That is because it uses getSailDistance and NOT the euclidean distance.

Parameters:
location -
border -
Returns:
closest point

getClosestSailDistance

public GameInfo.LocationPair getClosestSailDistance(List<Location> borderA,
                                                    List<Location> borderB)
Finds a closest point on given border to a given point. VERY ROUGH!!! That is because it uses getSailDistance and NOT the euclidean distance.

Parameters:
borderA -
borderB -
Returns:
two closest points

isValidTerritory

public boolean isValidTerritory(int teamId,
                                float longitude,
                                float latitude,
                                boolean seaArea)
True if the given coordinates belong to the given Team. If seaArea is set to true, then Coordinates must be on sea area, otherwise land. If teamId = -1, then function returns if coordinates are land or sea terrain respectively. Note that there can be coordinates which are neither land nor sea

Parameters:
teamId -
longitude -
latitude -
seaArea -
Returns:

isValidTerritory

public boolean isValidTerritory(int teamId,
                                double longitude,
                                double latitude,
                                boolean seaArea)
True if the given coordinates belong to the given Team. If seaArea is set to true, then Coordinates must be on sea area, otherwise land. If teamId = -1, then function returns if coordinates are land or sea terrain respectively. Note that there can be coordinates which are neither land nor sea

Parameters:
teamId -
longitude -
latitude -
seaArea -
Returns:

isValidTerritory

public boolean isValidTerritory(int teamId,
                                Location location,
                                boolean seaArea)
True if the given coordinates belong to the given Team. If seaArea is set to true, then Coordinates must be on sea area, otherwise land. If teamId = -1, then function returns if coordinates are land or sea terrain respectively. Note that there can be coordinates which are neither land nor sea

Parameters:
teamId -
location -
seaArea -
Returns:

isBorder

public boolean isBorder(float longitude,
                        float latitude)
True if given coordinates are on the border. Compare "data/earth/coastlines.bmp".

Parameters:
longitude -
latitude -
Returns:

getTerritoryId

public int getTerritoryId(float longitude,
                          float latitude)
Territory Id of territory at given coordinates.

Parameters:
longitude -
latitude -
Returns:

getTerritoryId

public int getTerritoryId(double longitude,
                          double latitude)
Territory Id of territory at given coordinates.

Parameters:
longitude -
latitude -
Returns:

getOwnTeamId

public int getOwnTeamId()
Own team id.

Returns:

getTeamIds

public int[] getTeamIds()
List of Team Ids in the game.

Returns:

getAlliancesWithTeamIds

public SortedMap<Integer,LinkedList<Integer>> getAlliancesWithTeamIds()
List of Alliances Team Ids in the game.

Returns:
List of enemy alliances and containing enemies WARNING: this SortedMap changes when someone leaves/enters alliance

getEnemyTeamIds

public int[] getEnemyTeamIds()
List of Enemy Team Ids in the game.

Returns:
List of enemy alliances and containing enemies WARNING: this SortedMap changes when someone leaves/enters alliance

getEnemiesCityIds

public SortedMap<Integer,List<Integer>> getEnemiesCityIds()
List of Enemies city Ids in the game.

Returns:
List of enemy alliances and containing enemies WARNING: this SortedMap changes when someone leaves/enters alliance

getEnemyCityIds

public List<Integer> getEnemyCityIds()
List of Enemies city Ids in the game.

Returns:
List of enemy alliances and containing enemies WARNING: this SortedMap changes when someone leaves/enters alliance

getEnemyCityIds

public List<Integer> getEnemyCityIds(int enemyId)
List of Enemy city Ids in the game.

Returns:
List of enemy alliances and containing enemies WARNING: this SortedMap changes when someone leaves/enters alliance

getTeamTerritoriesCount

public int getTeamTerritoriesCount(int teamId)
Number of territories for given team, usually 1.

Returns:

getTeamTerritories

public int[] getTeamTerritories(int teamId)
Territory Ids of territories that the given team owns. The enum TERRITORY_* relates the ids to starting positions

Parameters:
teamId -
Returns:
territories belonging to the team

getOwnTeamTerritories

public int[] getOwnTeamTerritories()
Territory Ids of territories that the team the player is in owns. The enum TERRITORY_* relates the ids to starting positions

Returns:
territories belonging to the team

getAllianceId

public int getAllianceId(int teamId)
Id of alliance. Each team belongs to exactly one alliance.

Parameters:
teamId -
Returns:

getDesiredGameSpeed

public int getDesiredGameSpeed(int teamId)
Currently requested game speed of given team.

Parameters:
teamId -
Returns:

getEnemyKills

public int getEnemyKills(int teamId)
Sum of enemy kills of the given team (for scoring).

Parameters:
teamId -
Returns:

getFriendlyDeaths

public int getFriendlyDeaths(int teamId)
Sum of friendly deaths (deaths in allied populations) of the given team.

Parameters:
teamId -
Returns:

getCollateralDamage

public int getCollateralDamage(int teamId)
Sum of collateral damage deaths (deaths in own population) of the given team.

Parameters:
teamId -
Returns:

getTeamName

public String getTeamName(int teamId)
Name of the given team.

Parameters:
teamId -
Returns:

isSharingRadar

public boolean isSharingRadar(int teamId1,
                              int teamId2)
True iff the first team is sharing its radar with the second team.

Parameters:
teamId1 -
teamId2 -
Returns:

isCeaseFire

public boolean isCeaseFire(int teamId1,
                           int teamId2)
True iff the first team is in cease fire mode with the second team.

Parameters:
teamId1 -
teamId2 -
Returns:

getFleetMemberOffset

public Location getFleetMemberOffset(int memberCount,
                                     int memberId)
Offset of ship number memberId from center of fleet, given fleet has memberCount ships

Parameters:
memberCount -
memberId -
Returns:

getRunning

public boolean getRunning()
Queries gameRunning flag.

Returns:
true if game is running.

isValidFleetPlacement

public boolean isValidFleetPlacement(Location placement,
                                     int fleetSize)
Simplifies queries for possibility of placing a fleet. Inspired by native bots implemented for Defcon API.

Parameters:
placement - location, where to check the placement validity.
fleetSize - number of units in the fleet.
Returns:
true if this placement is valid.

getFleetDiameter

public double getFleetDiameter(int fleetSize)
Gets the smallest circle diameter, which could contain the whole fleet.

Parameters:
fleetSize -
Returns:
diameter of the fleet of given size

getAllEnemyTerritories

public LinkedList<Integer> getAllEnemyTerritories()
Returns a flat list of territories possessed by enemies.

Returns:
flat list of all enemy territories

isValidStructureLocation

public boolean isValidStructureLocation(Location placement)
Checks validity of placement for structures.

Parameters:
placement - location, where to check the placement validity.
Returns:
true if this placement is valid.

getNukeSupply

public int getNukeSupply(int unitId)
Returns amount of nukes present in the given unit.

Parameters:
unitId -
Returns:
amount of nukes

getType

public UnitType getType(int unitId)
Returns type of unit with this id.

Parameters:
unitId - id of unit
Returns:

getStateCount

public int getStateCount(int unitId,
                         IState state)
Returns number of activations of this state for this unit.

Parameters:
unitId - id of unit
state - state for the unit
Returns:

getStateCount

public int getStateCount(int unitId,
                         int stateId)
Returns number of activations of this state for this unit.

Parameters:
unitId - id of unit
stateId - stateId for the unit
Returns:

getTerritoryOwners

public int[] getTerritoryOwners()
Returns the territory to owner mapping array.

Returns:

getTerritoryOwner

public int getTerritoryOwner(Location center)
Returns the owner of a land territory, which contains given location or -1 if noone owns it.

Parameters:
center -
Returns:

getTerritoryOwner

public int getTerritoryOwner(double longitude,
                             double latitude)
Returns the owner of a land territory, which contains given location or -1 if noone owns it.

Parameters:
longitude -
latitude -
Returns:

getTerritoryOwner

public int getTerritoryOwner(int territoryId)
Returns the owner of a territory with a given Id.

Parameters:
territoryId -
Returns:

getTerritoryId

public int getTerritoryId(Location location)
Get id of a land territory at a given location.

Parameters:
location -
Returns:

getTerritoriesCount

public int getTerritoriesCount()
Returns the number of territories.

Returns:

getCityIds

public int[] getCityIds()
Gets a list of cities.

Returns:

getObjectLocation

public Location getObjectLocation(int objectId)
Returns a location of the given object.

Parameters:
objectId -
Returns:

canCreateFleet

public boolean canCreateFleet(UnitType[] ships)
Checks whether are there enough units of each type to create a fleet of a given composition.

Parameters:
ships -
Returns:

getSubNukeRange

public double getSubNukeRange()
Returns range of submarine nukes (SRBM).

Returns:

getBomberRange

public double getBomberRange()
Returns range of a bomber.

Returns:

getRadarRange

public double getRadarRange()
Returns range of a single radar.

Returns:

getFighterRange

public double getFighterRange()
Returns range of a fighter.

Returns:

getSiloRange

public double getSiloRange()
Returns range of AA mode of a silo.

Returns:

getCitiesGravityCenter

public DefConLocation getCitiesGravityCenter(int teamId)
Returns center of gravity of given enemy's cities.

Parameters:
teamId -
Returns:

getCityLocation

public DefConLocation getCityLocation(int cityId)
Returns location of the given city.

Parameters:
cityId -
Returns:


Copyright © 2013 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.