Package net.royalur

Class Game

java.lang.Object
net.royalur.Game
All Implemented Interfaces:
TimeProvider

public class Game extends Object implements 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.
  • Constructor Details

    • Game

      public Game(RuleSet rules, GameMetadata metadata, List<GameState> states)
      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

      public Game(RuleSet rules)
      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

      protected Game(Game game)
      Instantiates a game of the Royal Game of Ur that is a copy of game.
      Parameters:
      game - The rules of the game.
  • Method Details

    • createUntimed

      public static Game createUntimed(RuleSet rules)
      Instantiates a new game of the Royal Game of Ur that is untimed.
      Parameters:
      rules - The rules of the game.
    • copy

      public Game copy()
      Generates a copy of this game.
      Returns:
      A copy of this.
    • addStates

      public void addStates(Iterable<GameState> states)
      Adds all states from states to this game.
      Parameters:
      states - The states to add to this game.
    • addState

      public void addState(GameState state)
      Adds the state state to this game.
      Parameters:
      state - The state to add to this game.
    • getRules

      public RuleSet 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

      public GameMetadata 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 interface TimeProvider
      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 interface TimeProvider
      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 interface TimeProvider
      Returns:
      The number of milliseconds elapsed since the start of the game.
    • getDice

      public Dice getDice()
      Gets the dice to are used to make dice rolls.
      Returns:
      The dice to be used to make dice rolls.
    • getStates

      public List<GameState> 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

      public GameState getState()
      Retrieve the state that the game is currently in.
      Returns:
      The state that the game is currently in.
    • getActionStates

      public List<ActionGameState> 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

      public List<GameState> 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

      public boolean hasPlayerMadeAnyActions(PlayerType player)
      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

      public boolean hasPlayerMadeAnyMoves(PlayerType player)
      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

      public PlayableGameState getPlayableState()
      Gets the current state of this game as a PlayableGameState. 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

      public WaitingForRollGameState getWaitingForRollState()
      Gets the current state of this game as an instance of WaitingForRollGameState. 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

      public WaitingForMoveGameState getWaitingForMoveState()
      Gets the current state of this game as an instance of WaitingForMoveGameState. 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

      @Nullable public ControlGameState getLastControlStateOrNull()
      Gets the last control state in this game, or null if there is no control state in this game.
      Returns:
      The last control state in this game, or null.
    • getResignedState

      public ResignedGameState getResignedState()
      Gets the last control state in this game as an instance of ResignedGameState. is no control state in this game.
      Returns:
      The last control state in this game, or null.
    • getAbandonedState

      public AbandonedGameState getAbandonedState()
      Gets the last control state in this game as an instance of AbandonedGameState. is no control state in this game.
      Returns:
      The last control state in this game, or null.
    • getEndState

      public EndGameState getEndState()
      Gets the current state of this game as an instance of EndGameState. This will throw an error if the game has not ended.
      Returns:
      The win state that the game is currently in.
    • rollDice

      public void rollDice(Roll roll)
      Rolls the dice, with a known value of roll, and updates the state of the game accordingly.
      Parameters:
      roll - The value of the dice that is to be rolled.
    • rollDice

      public Roll rollDice()
      Rolls the dice, and updates the state of the game accordingly.
      Returns:
      The value of the dice that were rolled.
    • rollDice

      public Roll rollDice(int value)
      Rolls the dice with a known value of value, 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

      public List<Move> findAvailableMoves()
      Finds all moves that can be made from the current position.
      Returns:
      All moves that can be made from the current position.
    • findMoveByPiece

      public Move findMoveByPiece(Piece piece)
      Finds the move of the piece piece.
      Parameters:
      piece - The piece to find the move for.
    • findMoveByTile

      public Move findMoveByTile(Tile sourceTile)
      Finds the move of the piece on tile.
      Parameters:
      sourceTile - The tile of the piece to find the move for.
    • findMoveIntroducingPiece

      public Move findMoveIntroducingPiece()
      Finds a move that introduces a new piece to the board.
      Returns:
      A move that introduces a new piece to the board.
    • findMoveScoringPiece

      public Move findMoveScoringPiece()
      Finds a move that scores a piece.
      Returns:
      A move that scores a piece.
    • move

      public void move(Move move)
      Applies the move move 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

      public void movePiece(Piece piece)
      Moves the piece piece, and updates the state of the game.
      Parameters:
      piece - The piece to be moved.
    • movePieceOnTile

      public void movePieceOnTile(Tile sourceTile)
      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

      public void resign(PlayerType player)
      Marks that player resigned the game.
      Parameters:
      player - The player to resign the game.
    • abandon

      public void abandon(AbandonReason reason, @Nullable PlayerType player)
      Marks that the game was abandoned due to reason. The person that abandoned the game can be provided using player, or null 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, or null.
    • wasResigned

      public boolean wasResigned()
      Gets whether a player resigned from this game.
      Returns:
      Whether a player resigned from this game.
    • getResigningPlayer

      public PlayerType 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

      public AbandonReason 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

      public PlayerType getAbandoningPlayer()
      Gets the player that abandoned the game.
      Returns:
      The player that abandoned the game.
    • getBoard

      public Board getBoard()
      Gets the current state of the board.
      Returns:
      The current state of the board.
    • getLightPlayer

      public PlayerState getLightPlayer()
      Gets the current state of the light player.
      Returns:
      The current state of the light player.
    • getDarkPlayer

      public PlayerState getDarkPlayer()
      Gets the current state of the dark player.
      Returns:
      The current state of the dark player.
    • getPlayer

      public PlayerState getPlayer(PlayerType player)
      Gets the current state of the player player.
      Parameters:
      player - The player to get the state of.
      Returns:
      The state of the player player.
    • getTurn

      public PlayerType 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

      public PlayerState getTurnPlayer()
      Gets the state of the player whose turn it is.
      Returns:
      The state of the player whose turn it is.
    • getWaiting

      public PlayerType 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

      public PlayerState 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

      public PlayerType 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

      public PlayerType getLoser()
      Gets the player that lost the game.
      Returns:
      The player that lost the game.
    • getWinningPlayer

      public PlayerState getWinningPlayer()
      Gets the state of the winning player.
      Returns:
      The state of the winning player.
    • getLosingPlayer

      public PlayerState getLosingPlayer()
      Gets the state of the losing player.
      Returns:
      The state of the losing player.
    • getTurnOrWinner

      public PlayerType 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

      public Roll 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

      public static GameBuilder builder()
      Creates a builder to assist in constructing games with custom settings.
    • create

      public static Game create(GameSettings settings)
      Creates a simple game with custom settings.
      Parameters:
      settings - The settings to use for the game.
      Returns:
      A game with custom settings.
    • createFinkel

      public static Game 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

      public static Game 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

      public static Game 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.