State.StateView

public static class StateView implements Serializable

Methods

canSee

public boolean canSee(int x, int y)

Returns whether the selected coordinates are visible to the player through the fog of war.

Parameters:
  • x
  • y

getAllResourceIds

public List<Integer> getAllResourceIds()

Get the IDs of all of the resource nodes that you can see

getAllResourceNodes

public List<ResourceNode.ResourceView> getAllResourceNodes()

Get the views of all of the resource nodes that you can see

getAllTemplateIds

public List<Integer> getAllTemplateIds()

Get the ids of all the templates. If you are not an observer, it will only give you yours if fog of war is on

getAllTemplates

public List<TemplateView> getAllTemplates()

Get the views of all the templates. If you are not an observer, it will only give you yours if fog of war is on

getAllUnitIds

public List<Integer> getAllUnitIds()

Get all of the unit ids that you can see

getAllUnits

public List<UnitView> getAllUnits()

Get views of all of the units that you can see

getClosestOpenPosition

public int[] getClosestOpenPosition(int x, int y)

Gets the closest position that you can see.

Parameters:
  • x
  • y

getPlayerNumbers

public Integer[] getPlayerNumbers()

Get the list of the player numbers of players in the map.

getResourceAmount

public Integer getResourceAmount(int playerid, ResourceType type)

Get the amount of wood or gold (specified by the type) available to a specific player. If you are not an observer, it will not work on other people with fog of war on

Parameters:
  • player
  • type – The type of resource

getResourceNode

public ResourceNode.ResourceView getResourceNode(int resourceID)

Get the resource node with the selected ID (if you can see it)

Parameters:
  • resourceID
Returns:

The resource node with id resourceID, or null if you can’t see it or if there isn’t one.

getResourceNodeIds

public List<Integer> getResourceNodeIds(ResourceNode.Type type)

Get the IDs of all of the resource nodes of a type that you can see

Parameters:
  • type – Gold mine or Tree

getResourceNodes

public List<ResourceNode.ResourceView> getResourceNodes(ResourceNode.Type type)

Get the views of all of the resource nodes of a type that you can see

Parameters:
  • type – Gold mine or Tree

getStateCreator

public StateCreator getStateCreator()

If the player can see the whole state, get a StateCreator that will rebuild the state as it is when this is called. This can be used as an immutable and repeatable deep copy of the underlying state.

Throws:
  • IOException
Returns:

When fog of war is on and the player is not an observer: null;otherwise: A StateCreator that rebuilds the underlying state.

getSupplyAmount

public Integer getSupplyAmount(int playerid)

Get the amount of supply (food) used by a specific player. If you are not an observer, it will not work on other people with fog of war on

Parameters:
  • player

getSupplyCap

public Integer getSupplyCap(int playerid)

Get the maximum amount of supply (food) available to a specific player. This should be used for calculating whether another unit can be made. If you are not an observer, it will not work on other people with fog of war on

Parameters:
  • player

getSupplyCapEarned

public Integer getSupplyCapEarned(int playerid)

Get the maximum amount of supply (food) earned by a specific player. This is the amount given by the farms and town halls or their alternatives. This should be used for calculating effect of farms/townhalls dying, not for calculating whether you can make a unit. If you are not an observer, it will not work on other people with fog of war on

Parameters:
  • player

getSupplyCapMaximum

public int getSupplyCapMaximum()

Get the maximum amount of supply that could ever be available to any player. This should be used in conjunction with getSupplyCapEarned to determine the effect of building a new farm/townhall.

getTemplate

public Template.TemplateView getTemplate(int templateID)

Get a template with a specific ID If you are not an observer, it won’t work with somebody else’s template with fog of war on

Parameters:
  • templateID

getTemplate

public Template.TemplateView getTemplate(int player, String name)

Get a template with that name owned by that player

Parameters:
  • player
  • name
Returns:

The view of the first (and what should be the only) template that has the specified name, or null if that player does not have a template by that name

getTemplateIds

public List<Integer> getTemplateIds(int playerid)

Get a player’s template IDs If you are not an observer, you can’t get other people’s templates if fog of war is on

Parameters:
  • playerid

getTemplates

public List<TemplateView> getTemplates(int playerid)

Get a player’s template views If you are not an observer, you can’t get other people’s templates if fog of war is on

Parameters:
  • playerid

getTurnNumber

public int getTurnNumber()

getUnit

public Unit.UnitView getUnit(int unitID)

Get the unit with the selected id if you can see it.

Parameters:
  • unitID
Returns:

The unit with that ID, null if you can’t see it or if it doesn’t exist

getUnitIds

public List<Integer> getUnitIds(int player)

Get the unit ids of those units owned by the selected players. Will give only your units when fog of war is on, unless you are an observer

Parameters:
  • player

getUnits

public List<UnitView> getUnits(int player)

Get the unit views of those units owned by the selected players. Will give only your units when fog of war is on, unless you are an observer

Parameters:
  • player

getXExtent

public int getXExtent()

Get how big the map is in the x direction

getYExtent

public int getYExtent()

Get how big the map is in the y direction

hasUnit

public boolean hasUnit(int playerNumber, int templateid)

Get whether a player has a unit of a certain type. (Say, a tech building). If you are not an observer, then this will not work on other players with fog of war on

Parameters:
  • playerNumber
  • buildingtemplateid
Returns:

Whether the player with id playerid has a unit with a template with the template id templateid, or false if the player is not you

hasUpgrade

public boolean hasUpgrade(int upgradeid, int playerid)

Get whether a player has researched a specific upgrade. If you are not an observer, then this will not work on other players with fog of war on

Parameters:
  • upgradeid
  • playerid
Returns:

Whether the player has researched an upgrade with id upgradeid. Always false if you try it on someone else.

inBounds

public boolean inBounds(int x, int y)

Find whether a position is in bounds.

Parameters:
  • x
  • y

isFogOfWar

public boolean isFogOfWar()

Get whether fog of war (partial observability) is activated

isResourceAt

public boolean isResourceAt(int x, int y)

Find whether there is a resource at the position

Parameters:
  • x
  • y
Returns:

Whether there is a resource there (always false if you can’t see there)

isUnitAt

public boolean isUnitAt(int x, int y)

Find if there is a unit at a position

Parameters:
  • x
  • y
Returns:

Whether there is a unit at the position (always false if you can’t see there)

resourceAt

public Integer resourceAt(int x, int y)

Get the resource at a position

Parameters:
  • x
  • y
Returns:

The resource’s ID, or null if there is no resource or if you can’t see the position

unitAt

public Integer unitAt(int x, int y)

Get the unit at a position

Parameters:
  • x
  • y
Returns:

The unit’s ID, or null if there is no unit (or if you can’t see there)