public class GameState
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
int |
currentPlayer
the player number on move 1..N
|
java.util.Map<java.lang.String,java.lang.String> |
elementLocations
for each element name, location name where it currently is placed
|
java.util.Map<java.lang.String,java.lang.Integer> |
elementOwners
for each element name, the number of player
|
java.util.Map<java.lang.String,java.lang.Integer> |
elementStates
for each element name, the state number
|
java.util.Map<java.lang.String,java.lang.Integer> |
elementzIndexes
z-indexes of all the elements
|
java.util.Map<java.lang.String,java.lang.String> |
locationElements
for each location, content of the element
|
int[] |
playerScores
scores of all players
|
int |
winner
-1 until the game has finished, then 0 for draw, or 1..N player number who won
|
Constructor and Description |
---|
GameState()
construct a new empty game state
|
GameState(GameSpecification specs,
Robot robot)
use this constructor to create a state corresponding to the start of game situation
|
Modifier and Type | Method and Description |
---|---|
java.util.ArrayList<Move> |
allPossibleMoves()
return a list of moves that can be taken from this state - this includes ALL moves regardless that they are equal (because of irrelevance of locations or same element types)
|
boolean |
equals(GameState other)
implementation of the equals() method - we ignore irrelevant locations and look only at element types, not the element names
|
boolean |
equals(java.lang.Object other)
determine if the state is equal to another one - while ignoring irrelevant locations
|
Move |
findMove(GameState newState)
compares this state with newState, and returns a move that leads from this state to a new state
|
GameState |
getCopy()
return a copy of this state state
|
int |
hashCode()
return a hash code for fast hashmap access, remember to call touch() always after state changes
|
boolean |
moveAllowed(Move move)
verifies all rules, returns true, if the move is allowed, or false if not,
does not modify the game state, does not make any followup actions, however
executes all conditions of tested rules with all the consequences
|
void |
moveElement(Move move,
GameSpecification specs)
only updates the game state by moving element between two locations, does not test anything, does not apply any rules
|
void |
performMove(Move move)
performs a move after it has been verified, executes follow-up action
of the rule that maximizes the score, adds the score, important: the
game is marked finished only if one of the players won, or rules
specifically announced draw.
|
java.util.HashSet<Move> |
possibleMoves()
return a list of moves that can be taken from this states - this includes only DIFFERENT moves, i.e.
|
java.lang.String |
toString() |
void |
touch()
always call this method after modifying the state
|
public java.util.Map<java.lang.String,java.lang.Integer> elementStates
public java.util.Map<java.lang.String,java.lang.String> elementLocations
public java.util.Map<java.lang.String,java.lang.String> locationElements
public java.util.Map<java.lang.String,java.lang.Integer> elementOwners
public int currentPlayer
public int winner
public java.util.Map<java.lang.String,java.lang.Integer> elementzIndexes
public int[] playerScores
public GameState()
public GameState(GameSpecification specs, Robot robot)
public GameState getCopy()
public java.lang.String toString()
toString
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public void touch()
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public boolean equals(GameState other)
public Move findMove(GameState newState)
public java.util.ArrayList<Move> allPossibleMoves() throws java.lang.Exception
java.lang.Exception
public java.util.HashSet<Move> possibleMoves() throws java.lang.Exception
java.lang.Exception
public boolean moveAllowed(Move move) throws java.lang.Exception
java.lang.Exception
public void performMove(Move move) throws java.lang.Exception
java.lang.Exception
public void moveElement(Move move, GameSpecification specs)