State

public class State implements Serializable, Cloneable, IDDistributer, DeepEquatable

Represents the state

Constructors

State

public State()

Methods

addPlayer

public void addPlayer(int playernumber)

Add another player

Parameters:
  • playernumber – The player number of the player to add

addResource

public void addResource(ResourceNode resource)

addResourceAmount

public void addResourceAmount(int player, ResourceType type, int amount)

Adds an amount of a resource to a player’s global amount.

Parameters:
  • player
  • type
  • amount

addTemplate

public void addTemplate(Template t)

addUnit

public void addUnit(Unit u, int x, int y)

addUpgrade

public void addUpgrade(Upgrade upgrade)

canSee

public boolean canSee(int x, int y, int player)

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

Parameters:
  • x
  • y
  • player

checkValidSupplyAddition

public boolean checkValidSupplyAddition(int player, int amounttoadd, int offsettingcapgain)

deepEquals

public boolean deepEquals(Object other)

A deep equals method, because the equals methods of many classes have been hijacked into ID comparison for performance reasons

Parameters:
  • other

getClosestPosition

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

Find the closest unoccupied position using a spiraling out search pattern

Parameters:
  • x
  • y

getFogOfWar

public boolean getFogOfWar()

getNextTargetIDForXMLSave

public int getNextTargetIDForXMLSave()

DON’T USE THIS IF YOU AREN’T THE XML SAVING MECHANISM This must be different from the other so saves in the middle of an episode don’t mess up the ids

getNextTemplateIDForXMLSave

public int getNextTemplateIDForXMLSave()

DON’T USE THIS IF YOU AREN’T THE XML SAVING MECHANISM This must be different from the other so saves in the middle of an episode don’t mess up the ids

getPlayerState

public PlayerState getPlayerState(int player)

getPlayerStates

public Collection<PlayerState> getPlayerStates()

getPlayers

public Integer[] getPlayers()

Return an array of the players currently in the game

getResource

public ResourceNode getResource(int resourceId)

getResourceAmount

public int getResourceAmount(int player, ResourceType type)

getResources

public List<ResourceNode> getResources()

getStateCreator

public StateCreator getStateCreator()

Get a StateCreator that will duplicate what this state looks like when the function is called.

Throws:
  • IOException

getSupplyAmount

public int getSupplyAmount(int player)

getSupplyCap

public int getSupplyCap(int player)

getSupplyCapEarned

public int getSupplyCapEarned(int player)

getTemplate

public Template getTemplate(int templateId)

getTemplate

public Template getTemplate(int player, String name)

getTemplates

public Map<Integer, Template> getTemplates(int player)

getTextString

public String getTextString()

Get a limited, but text-friendly, version of the state.

getTurnNumber

public int getTurnNumber()

getUnit

public Unit getUnit(int unitId)

getUnits

public Map<Integer, Unit> getUnits(int player)

getUnits

public Map<Integer, Unit> getUnits()

getView

public StateView getView(int player)

getXExtent

public int getXExtent()

getYExtent

public int getYExtent()

hasUnit

public boolean hasUnit(int player, int templateid)

hasUpgrade

public boolean hasUpgrade(int player, Integer upgradetemplateid)

inBounds

public boolean inBounds(int x, int y)

incrementTurn

public void incrementTurn()

Go to the next turn. Increases the turn number and tells the logs to go to the next turn

moveUnit

public void moveUnit(Unit u, Direction direction)

Move a unit in a direction. Does not perform collision checks of any kind

Parameters:
  • u
  • direction

nextTargetID

public int nextTargetID()

nextTemplateID

public int nextTemplateID()

positionAvailable

public boolean positionAvailable(int x, int y)

recalculateVision

public void recalculateVision()

Recalculates the vision of each agent from scratch.

removeResourceNode

public void removeResourceNode(int resourceID)

removeUnit

public void removeUnit(int unitID)

resourceAt

public ResourceNode resourceAt(int x, int y)

setFogOfWar

public void setFogOfWar(boolean fogofwar)

setSize

public void setSize(int x, int y)

transportUnit

public void transportUnit(Unit u, int newx, int newy)

Move a unit from one place to another and update the sight radius. For use in the rare cases where a single direction is insufficient.

Parameters:
  • u – The unit to move
  • newx – The new x position of the unit
  • newy – The new y position of the unit

tryProduceUnit

public boolean tryProduceUnit(Unit u, int x, int y)

tryProduceUpgrade

public boolean tryProduceUpgrade(Upgrade upgrade)

unitAt

public Unit unitAt(int x, int y)

updateGlobalListsFromPlayers

public void updateGlobalListsFromPlayers()

Used as a necessary part of loading from xml. Harmless but pointless to use otherwise.