Package com.c1games.terminal.algo.map
Class GameState
java.lang.Object
com.c1games.terminal.algo.map.GameState
public class GameState
extends java.lang.Object
An object derived from frame data which can be used to compose a move, before eventually sending it into the GameIO object.
This object contains a random-access representation of the map state and all its units, which can be used to query for information about the
game, including move legality.
This object keeps a buffer of unit placements, which will be serialized and sent to the game engine upon making of the move.
-
Field Summary
Fields Modifier and Type Field Description java.util.List<Unit>[][]
allUnits
Config
config
FrameData
data
static int
TowerUnitCategory
static int
WalkerUnitCategory
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description int
attemptRemoveStructure(Coords coords)
int
attemptRemoveStructureMultiple(java.util.List<Coords> coords)
boolean
attemptSpawn(Coords location, UnitType type)
Spawn a unit in a location if able, returning whether it successfully spawned the unit.int
attemptSpawnMultiple(java.util.List<Coords> locations, UnitType type)
Spawn a certain unit type in as many locations as possible, returning the number successful.int
attemptUpgrade(Coords coords)
int
attemptUpgradeMultiple(java.util.List<Coords> coords)
CanRemove
canRemoveStructure(Coords coords)
Result of whether a structure can be removed at a location.CanSpawn
canSpawn(Coords coords, UnitType type, int quantity)
Result of whether a unit can be spawned at a location.java.util.List<Unit>
getAttackers(Coords coords)
java.util.List<Unit>
getInfoAt(Coords coords)
Could return empty listboolean
getRemoveAt(Coords coords)
Nullable.java.util.List<java.util.List<SpawnCommand>>
getSpawnCommands()
Get the spawn commands necessary to submit to the engine to take this turn.Unit
getWallAt(Coords coords)
Nullable.boolean
isInfo(int category)
boolean
isInfo(UnitType type)
boolean
isStructure(int category)
boolean
isStructure(UnitType type)
int
numberAffordable(UnitType type)
How many of a certain unit type we can afford.int
numberAffordable(UnitType type, boolean upgrade)
How many of a certain unit type we can afford.java.util.List<Coords>
pathfind(Coords start, int targetEdge)
Use the code within the pathfinding package to compute the path that a mobile unit would take if placed on a particular coordinate, assuming that the layout of the walls do not change.void
placeUpgrade(Coords loc)
void
removeStructure(Coords coords)
Attempt to remove an existing structure that we own, or throw an exception if unable.void
spawn(Coords coords, UnitType type)
Attempt to spawn a unit at a location, or throw an exception if unable.UnitType
unitTypeFromShorthand(java.lang.String shorthand)
-
Field Details
-
TowerUnitCategory
public static final int TowerUnitCategory- See Also:
- Constant Field Values
-
WalkerUnitCategory
public static final int WalkerUnitCategory- See Also:
- Constant Field Values
-
config
-
data
-
allUnits
-
-
Constructor Details
-
Method Details
-
getInfoAt
Could return empty list -
isStructure
-
isInfo
-
isStructure
public boolean isStructure(int category) -
isInfo
public boolean isInfo(int category) -
unitTypeFromShorthand
-
getWallAt
Nullable. -
getRemoveAt
Nullable. Only checks whether there is a remove unit at that particular location, denoting whether we have removed a structure at that unit. Does not actually remove the unit. -
canSpawn
Result of whether a unit can be spawned at a location. -
spawn
Attempt to spawn a unit at a location, or throw an exception if unable. This will alter the data within GameState and FrameData as if this operation proceeded (unless an exception is thrown) so that further operations can be applied correctly. This should be paired with @code canSpawn to avoid the exception.- Throws:
CannotSpawnException
-
attemptSpawn
Spawn a unit in a location if able, returning whether it successfully spawned the unit. -
attemptSpawnMultiple
Spawn a certain unit type in as many locations as possible, returning the number successful. -
canRemoveStructure
Result of whether a structure can be removed at a location. -
removeStructure
Attempt to remove an existing structure that we own, or throw an exception if unable. This will alter the data within GameState and FrameData as if this operation proceeded (unless an exception is thrown) so that further operations can be applied correctly. This should be paired with @code canRemove to avoid the exception.- Throws:
CannotRemoveException
-
attemptRemoveStructure
-
attemptRemoveStructureMultiple
-
attemptUpgrade
-
attemptUpgradeMultiple
-
placeUpgrade
-
numberAffordable
How many of a certain unit type we can afford. -
numberAffordable
How many of a certain unit type we can afford. -
getSpawnCommands
Get the spawn commands necessary to submit to the engine to take this turn. This is generally used by implementations of gameio. -
pathfind
public java.util.List<Coords> pathfind(Coords start, int targetEdge) throws IllegalPathStartExceptionUse the code within the pathfinding package to compute the path that a mobile unit would take if placed on a particular coordinate, assuming that the layout of the walls do not change. Throws an IllegalPathStartExceptions if a unit could not be placed in that location.s- Throws:
IllegalPathStartException
-
getAttackers
-