Package net.royalur.rules.state
Class GameState
java.lang.Object
net.royalur.rules.state.GameState
- Direct Known Subclasses:
ControlGameState
,EndGameState
,OngoingGameState
A game state represents a single point within a game.
-
Constructor Summary
ConstructorsConstructorDescriptionGameState
(Board board, PlayerState lightPlayer, PlayerState darkPlayer, long timeSinceGameStartMs) Instantiates a game state. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addMetadata
(String key, String value) Add a piece of metadata to this state.void
addMetadata
(Map<String, String> entries) Adds many pieces of metadata to this state.void
Removes all metadata from this state.abstract String
describe()
Generates an English text description of the state of the game.boolean
getBoard()
Get the state of the pieces on the board.Get the state of the dark player.Get the state of the light player.Gets the metadata associated with this state.getMetadata
(String key) Retrieves the value of a specific metadata entry.getPlayerState
(PlayerType player) Gets the state of the playerplayer
.abstract PlayerType
Get the subject player of the game state. e.g., player to roll/move, player that rolled/moved, player that won.long
Gets the time this state was created, measured by the number of milliseconds elapsed since the start of the game.boolean
hasMetadata
(String key) Checks whether this state has metadata associated with the given key.abstract boolean
Returns whether this state represents a finished game.abstract boolean
Returns whether this state is a valid state to be played from.removeMetadata
(String key) Removes a piece of metadata from this state.
-
Constructor Details
-
GameState
public GameState(Board board, PlayerState lightPlayer, PlayerState darkPlayer, long timeSinceGameStartMs) Instantiates a game state.- Parameters:
board
- The state of the pieces on the board.lightPlayer
- The state of the light player.darkPlayer
- The state of the dark player.timeSinceGameStartMs
- The time this state was created.
-
-
Method Details
-
getBoard
Get the state of the pieces on the board.- Returns:
- The state of the pieces on the board.
-
getLightPlayer
Get the state of the light player.- Returns:
- The state of the light player.
-
getDarkPlayer
Get the state of the dark player.- Returns:
- The state of the dark player.
-
getPlayerState
Gets the state of the playerplayer
.- Parameters:
player
- The player to retrieve the state of.- Returns:
- The state of the player
player
.
-
getTimeSinceGameStartMs
public long getTimeSinceGameStartMs()Gets the time this state was created, measured by the number of milliseconds elapsed since the start of the game.- Returns:
- The time this state was created.
-
addMetadata
Add a piece of metadata to this state.- Parameters:
key
- The identifier for the metadata to add.value
- The value associated with the key.
-
addMetadata
Adds many pieces of metadata to this state.- Parameters:
entries
- The pieces of metadata to add.
-
removeMetadata
Removes a piece of metadata from this state.- Parameters:
key
- The identifier for the metadata to remove.- Returns:
- The value that was associated with the key, or null if none existed.
-
clearMetadata
public void clearMetadata()Removes all metadata from this state. -
hasMetadata
Checks whether this state has metadata associated with the given key.- Parameters:
key
- The identifier to check for.- Returns:
- Whether the key exists in the metadata.
-
getMetadata
Retrieves the value of a specific metadata entry.- Parameters:
key
- The identifier of the metadata to retrieve.- Returns:
- The value associated with the key, or null if none exists.
-
getMetadata
Gets the metadata associated with this state.- Returns:
- The metadata associated with this state.
-
getSubject
Get the subject player of the game state. e.g., player to roll/move, player that rolled/moved, player that won. -
isPlayable
public abstract boolean isPlayable()Returns whether this state is a valid state to be played from.- Returns:
- Whether this state is a valid state to be played from.
-
isFinished
public abstract boolean isFinished()Returns whether this state represents a finished game.- Returns:
- Whether this state represents a finished game.
-
describe
Generates an English text description of the state of the game.- Returns:
- An English text description of the state of the game.
-
equals
-