Package net.royalur
Class Game
java.lang.Object
net.royalur.Game
- All Implemented Interfaces:
TimeProvider
A game of the Royal Game of Ur. Provides methods to allow the playing of games,
and methods to support the retrieval of history about the moves that were made.
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.royalur.rules.TimeProvider
TimeProvider.Timed, TimeProvider.Untimed
-
Constructor Summary
ModifierConstructorDescriptionprotected
Instantiates a game of the Royal Game of Ur that is a copy ofgame
.Instantiates a game of the Royal Game of Ur that has not yet had any moves played.Game
(RuleSet rules, GameMetadata metadata, List<GameState> states) Instantiates a game of the Royal Game of Ur. -
Method Summary
Modifier and TypeMethodDescriptionvoid
abandon
(AbandonReason reason, PlayerType player) Marks that the game was abandoned due toreason
.void
Adds the statestate
to this game.void
Adds all states fromstates
to this game.static GameBuilder
builder()
Creates a builder to assist in constructing games with custom settings.copy()
Generates a copy of this game.static Game
create
(GameSettings settings) Creates a simple game with custom settings.static Game
Creates a game of Aseb.static Game
Creates a game that follows the rules proposed by Irving Finkel.static Game
Creates a game that follows the rules proposed by James Masters.static Game
createUntimed
(RuleSet rules) Instantiates a new game of the Royal Game of Ur that is untimed.Finds all moves that can be made from the current position.findMoveByPiece
(Piece piece) Finds the move of the piecepiece
.findMoveByTile
(Tile sourceTile) Finds the move of the piece ontile
.Finds a move that introduces a new piece to the board.Finds a move that scores a piece.Gets the last control state in this game as an instance ofAbandonedGameState
.Gets the player that abandoned the game.Gets the reason this game was abandoned.Gets the states that represent the actions that have been made so far in the game.getBoard()
Gets the current state of the board.Gets the current state of the dark player.getDice()
Gets the dice to are used to make dice rolls.Gets the current state of this game as an instance ofEndGameState
.long
Gets the start time of the game in milliseconds since the epoch.Gets all moves that were made in the game, as well as the current state of the game.Gets the last control state in this game, ornull
if there is no control state in this game.Gets the current state of the light player.getLoser()
Gets the player that lost the game.Gets the state of the losing player.Gets the metadata of this game.Gets the current state of this game as aPlayableGameState
.getPlayer
(PlayerType player) Gets the current state of the playerplayer
.Gets the last control state in this game as an instance ofResignedGameState
.Gets the player that resigned from this game.getRoll()
Gets the roll that was made that can be used by the current turn player to make a move.getRules()
Gets the set of rules that are being used for this game.getState()
Retrieve the state that the game is currently in.Gets the states that have occurred so far in the game.long
Gets the number of milliseconds elapsed since the start of the game.getTurn()
Gets the player who can make the next interaction with the game.Gets the player who can make the next interaction with the game, or the winner of the game if it is finished.Gets the state of the player whose turn it is.Gets the player that is waiting whilst the other player makes the next interaction with the game.Gets the current state of this game as an instance ofWaitingForMoveGameState
.Gets the current state of this game as an instance ofWaitingForRollGameState
.Gets the state of the player that is waiting as it is not their turn.Gets the player that won the game.Gets the state of the winning player.boolean
hasLoser()
Gets whether this game has a winner.boolean
hasPlayerMadeAnyActions
(PlayerType player) Checks whether the given player has made any actions in this game.boolean
hasPlayerMadeAnyMoves
(PlayerType player) Checks whether the given player has made any moves in this game.boolean
Gets whether this game has a winner.boolean
Checks whether the game is currently in a finished state.boolean
Determines whether the game is currently in a playable state.boolean
isTimed()
Checks whether this time provider produces values other than zero.boolean
Checks whether the game is currently waiting for a move from a player.boolean
Determines whether the game is currently waiting for a roll from a player.void
Applies the movemove
to update the state of the game.void
Moves the piecepiece
, and updates the state of the game.void
movePieceOnTile
(Tile sourceTile) Moves the piece on the given source tile, and updates the state of the game.void
resign
(PlayerType player) Marks thatplayer
resigned the game.rollDice()
Rolls the dice, and updates the state of the game accordingly.rollDice
(int value) Rolls the dice with a known value ofvalue
, and updates the state of the game accordingly.void
Rolls the dice, with a known value ofroll
, and updates the state of the game accordingly.boolean
Gets whether this game was abandoned.boolean
Gets whether a specific player abandoned the game.boolean
Gets whether a player resigned from this game.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.royalur.rules.TimeProvider
getGameStartTime
-
Constructor Details
-
Game
Instantiates a game of the Royal Game of Ur.- Parameters:
rules
- The set of rules that are being used for this game.metadata
- The metadata of this game.states
- The states that have occurred so far in the game.
-
Game
Instantiates a game of the Royal Game of Ur that has not yet had any moves played.- Parameters:
rules
- The rules of the game.
-
Game
Instantiates a game of the Royal Game of Ur that is a copy ofgame
.- Parameters:
game
- The rules of the game.
-
-
Method Details
-
createUntimed
Instantiates a new game of the Royal Game of Ur that is untimed.- Parameters:
rules
- The rules of the game.
-
copy
Generates a copy of this game.- Returns:
- A copy of
this
.
-
addStates
Adds all states fromstates
to this game.- Parameters:
states
- The states to add to this game.
-
addState
Adds the statestate
to this game.- Parameters:
state
- The state to add to this game.
-
getRules
Gets the set of rules that are being used for this game.- Returns:
- The set of rules that are being used for this game.
-
getMetadata
Gets the metadata of this game.- Returns:
- The metadata of this game.
-
isTimed
public boolean isTimed()Description copied from interface:TimeProvider
Checks whether this time provider produces values other than zero.- Specified by:
isTimed
in interfaceTimeProvider
- Returns:
- Whether this time provider produces values other than zero.
-
getGameStartEpochMs
public long getGameStartEpochMs()Description copied from interface:TimeProvider
Gets the start time of the game in milliseconds since the epoch. If this provider is untimed,0
will be returned instead.- Specified by:
getGameStartEpochMs
in interfaceTimeProvider
- Returns:
- The start time of the game in milliseconds since the epoch.
-
getTimeSinceGameStartMs
public long getTimeSinceGameStartMs()Description copied from interface:TimeProvider
Gets the number of milliseconds elapsed since the start of the game.- Specified by:
getTimeSinceGameStartMs
in interfaceTimeProvider
- Returns:
- The number of milliseconds elapsed since the start of the game.
-
getDice
Gets the dice to are used to make dice rolls.- Returns:
- The dice to be used to make dice rolls.
-
getStates
Gets the states that have occurred so far in the game. The last state in the list is the current state of the game.- Returns:
- The states that have occurred so far in the game.
-
getState
Retrieve the state that the game is currently in.- Returns:
- The state that the game is currently in.
-
getActionStates
Gets the states that represent the actions that have been made so far in the game. The last state in the list represents the last action that was taken in this game.- Returns:
- The states that represent the actions that have been made so far in the game.
-
getLandmarkStates
Gets all moves that were made in the game, as well as the current state of the game. These states are considered landmark states as they contain all the information required to recreate everything that happened in the game so far. -
isPlayable
public boolean isPlayable()Determines whether the game is currently in a playable state.- Returns:
- Whether the game is currently in a playable state.
-
isWaitingForRoll
public boolean isWaitingForRoll()Determines whether the game is currently waiting for a roll from a player.- Returns:
- Whether the game is currently waiting for a roll from a player.
-
isWaitingForMove
public boolean isWaitingForMove()Checks whether the game is currently waiting for a move from a player.- Returns:
- Whether the game is currently waiting for a move from a player.
-
isFinished
public boolean isFinished()Checks whether the game is currently in a finished state.- Returns:
- Whether the game is currently in a finished state.
-
hasPlayerMadeAnyActions
Checks whether the given player has made any actions in this game.- Parameters:
player
- The player to check.- Returns:
- Whether the given player has made any actions in this game.
-
hasPlayerMadeAnyMoves
Checks whether the given player has made any moves in this game.- Parameters:
player
- The player to check.- Returns:
- Whether the given player has made any moves in this game.
-
getPlayableState
Gets the current state of this game as aPlayableGameState
. This will throw an error if the game is not in a playable state.- Returns:
- The playable state that the game is currently in.
-
getWaitingForRollState
Gets the current state of this game as an instance ofWaitingForRollGameState
. This will throw an error if the game is not waiting for a roll from a player.- Returns:
- The waiting for roll state that the game is currently in.
-
getWaitingForMoveState
Gets the current state of this game as an instance ofWaitingForMoveGameState
. This will throw an error if the game is not waiting for a move from a player.- Returns:
- The waiting for move state that the game is currently in.
-
getLastControlStateOrNull
Gets the last control state in this game, ornull
if there is no control state in this game.- Returns:
- The last control state in this game, or
null
.
-
getResignedState
Gets the last control state in this game as an instance ofResignedGameState
. is no control state in this game.- Returns:
- The last control state in this game, or
null
.
-
getAbandonedState
Gets the last control state in this game as an instance ofAbandonedGameState
. is no control state in this game.- Returns:
- The last control state in this game, or
null
.
-
getEndState
Gets the current state of this game as an instance ofEndGameState
. This will throw an error if the game has not ended.- Returns:
- The win state that the game is currently in.
-
rollDice
Rolls the dice, with a known value ofroll
, and updates the state of the game accordingly.- Parameters:
roll
- The value of the dice that is to be rolled.
-
rollDice
Rolls the dice, and updates the state of the game accordingly.- Returns:
- The value of the dice that were rolled.
-
rollDice
Rolls the dice with a known value ofvalue
, and updates the state of the game accordingly.- Parameters:
value
- The value of the dice to be rolled.- Returns:
- The value of the dice that were rolled.
-
findAvailableMoves
Finds all moves that can be made from the current position.- Returns:
- All moves that can be made from the current position.
-
findMoveByPiece
Finds the move of the piecepiece
.- Parameters:
piece
- The piece to find the move for.
-
findMoveByTile
Finds the move of the piece ontile
.- Parameters:
sourceTile
- The tile of the piece to find the move for.
-
findMoveIntroducingPiece
Finds a move that introduces a new piece to the board.- Returns:
- A move that introduces a new piece to the board.
-
findMoveScoringPiece
Finds a move that scores a piece.- Returns:
- A move that scores a piece.
-
move
Applies the movemove
to update the state of the game. This does not check whether the move is valid.- Parameters:
move
- The move to make from the current state of the game.
-
movePiece
Moves the piecepiece
, and updates the state of the game.- Parameters:
piece
- The piece to be moved.
-
movePieceOnTile
Moves the piece on the given source tile, and updates the state of the game.- Parameters:
sourceTile
- The tile where the piece to be moved resides.
-
resign
Marks thatplayer
resigned the game.- Parameters:
player
- The player to resign the game.
-
abandon
Marks that the game was abandoned due toreason
. The person that abandoned the game can be provided usingplayer
, ornull
can be passed if a specific player did not abandon the game. For example, if a game had to end due to a venue closing, a player should not be provided.- Parameters:
reason
- The reason the game was abandoned.player
- The player that abandoned the game, ornull
.
-
wasResigned
public boolean wasResigned()Gets whether a player resigned from this game.- Returns:
- Whether a player resigned from this game.
-
getResigningPlayer
Gets the player that resigned from this game.- Returns:
- The player that resigned from this game.
-
wasAbandoned
public boolean wasAbandoned()Gets whether this game was abandoned.- Returns:
- Whether this game was abandoned.
-
getAbandonReason
Gets the reason this game was abandoned.- Returns:
- The reason this game was abandoned.
-
wasAbandonedByPlayer
public boolean wasAbandonedByPlayer()Gets whether a specific player abandoned the game.- Returns:
- Whether a specific player abandoned the game.
-
getAbandoningPlayer
Gets the player that abandoned the game.- Returns:
- The player that abandoned the game.
-
getBoard
Gets the current state of the board.- Returns:
- The current state of the board.
-
getLightPlayer
Gets the current state of the light player.- Returns:
- The current state of the light player.
-
getDarkPlayer
Gets the current state of the dark player.- Returns:
- The current state of the dark player.
-
getPlayer
Gets the current state of the playerplayer
.- Parameters:
player
- The player to get the state of.- Returns:
- The state of the player
player
.
-
getTurn
Gets the player who can make the next interaction with the game.- Returns:
- The player who can make the next interaction with the game.
-
getTurnPlayer
Gets the state of the player whose turn it is.- Returns:
- The state of the player whose turn it is.
-
getWaiting
Gets the player that is waiting whilst the other player makes the next interaction with the game.- Returns:
- The player who is waiting for the other player to interact with the game.
-
getWaitingPlayer
Gets the state of the player that is waiting as it is not their turn.- Returns:
- The state of the player that is waiting as it is not their turn.
-
hasWinner
public boolean hasWinner()Gets whether this game has a winner.- Returns:
- Whether this game has a winner.
-
getWinner
Gets the player that won the game.- Returns:
- The player that won the game.
-
hasLoser
public boolean hasLoser()Gets whether this game has a winner.- Returns:
- Whether this game has a winner.
-
getLoser
Gets the player that lost the game.- Returns:
- The player that lost the game.
-
getWinningPlayer
Gets the state of the winning player.- Returns:
- The state of the winning player.
-
getLosingPlayer
Gets the state of the losing player.- Returns:
- The state of the losing player.
-
getTurnOrWinner
Gets the player who can make the next interaction with the game, or the winner of the game if it is finished.- Returns:
- The player who can make the next interaction with the game, or the winner of the game if it is finished.
-
getRoll
Gets the roll that was made that can be used by the current turn player to make a move.- Returns:
- The roll that was made that can now be used to make a move.
-
builder
Creates a builder to assist in constructing games with custom settings. -
create
Creates a simple game with custom settings.- Parameters:
settings
- The settings to use for the game.- Returns:
- A game with custom settings.
-
createFinkel
Creates a game that follows the rules proposed by Irving Finkel. This uses the simple rules, the standard board shape, Bell's path, safe rosette tiles, the standard dice, and seven starting pieces per player.- Returns:
- A game that follows Irving Finkel's proposed simple rules.
-
createMasters
Creates a game that follows the rules proposed by James Masters. This uses the simple rules, the standard board shape, Bell's path, unsafe rosette tiles, three binary dice where 0 allows moving 4 tiles, and seven starting pieces per player.- Returns:
- A game that follows Irving Finkel's proposed simple rules.
-
createAseb
Creates a game of Aseb. This uses the simple rules, the Aseb board shape, the Aseb paths, the standard dice, and five starting pieces per player.- Returns:
- A game of Aseb.
-