Class RuleSet

java.lang.Object
net.royalur.rules.RuleSet
Direct Known Subclasses:
SimpleRuleSet

public abstract class RuleSet extends Object
A set of rules that govern the play of a game of the Royal Game of Ur.
  • Field Details

    • boardShape

      protected final BoardShape boardShape
      The shape of the game board.
    • paths

      protected final PathPair paths
      The paths that each player must take around the board.
    • diceFactory

      protected final DiceFactory diceFactory
      The generator of dice that are used to generate dice rolls.
    • sampleDice

      protected final Dice sampleDice
      A sample dice that can be used for parsing, but should not be used for running games.
    • pieceProvider

      protected final PieceProvider pieceProvider
      Provides the manipulation of piece values.
    • playerStateProvider

      protected final PlayerStateProvider playerStateProvider
      Provides the manipulation of player state values.
  • Constructor Details

    • RuleSet

      protected RuleSet(BoardShape boardShape, PathPair paths, DiceFactory diceFactory, PieceProvider pieceProvider, PlayerStateProvider playerStateProvider)
      Instantiates a rule set for the Royal Game of Ur.
      Parameters:
      boardShape - The shape of the game board.
      paths - The paths that the players must take around the board.
      diceFactory - The generator of dice that are used to generate dice rolls.
      pieceProvider - Provides the manipulation of piece values.
      playerStateProvider - Provides the manipulation of player states.
  • Method Details

    • getSettings

      public GameSettings getSettings()
      Get the settings used for this rule set.
      Returns:
      The settings used for this rule set.
    • getBoardShape

      public BoardShape getBoardShape()
      Gets the shape of the board used in this rule set.
      Returns:
      The shape of the game board.
    • getPaths

      public PathPair getPaths()
      Gets the paths that the players must take around the board.
      Returns:
      The paths that players must take around the board.
    • getDiceFactory

      public DiceFactory getDiceFactory()
      Gets the generator of dice that are used to generate dice rolls.
      Returns:
      The generator of dice that are used to generate dice rolls.
    • getSampleDice

      public Dice getSampleDice()
      Gets a sample dice that can be used for parsing, but should not be used for running games.
      Returns:
      A sample dice that can be used for parsing.
    • getPieceProvider

      public PieceProvider getPieceProvider()
      Gets the provider of piece manipulations.
      Returns:
      The provider of making piece changes.
    • getPlayerStateProvider

      public PlayerStateProvider getPlayerStateProvider()
      Gets the provider of player state manipulations.
      Returns:
      The provider of making player state changes.
    • areRosettesSafe

      public abstract boolean areRosettesSafe()
      Gets whether rosettes are considered safe squares in this rule set.
      Returns:
      Whether rosettes are considered safe squares in this rule set.
    • doRosettesGrantExtraRolls

      public abstract boolean doRosettesGrantExtraRolls()
      Gets whether landing on rosette tiles grants an additional roll.
      Returns:
      Whether landing on rosette tiles grants an additional roll.
    • doCapturesGrantExtraRolls

      public abstract boolean doCapturesGrantExtraRolls()
      Gets whether capturing a piece grants an additional roll.
      Returns:
      Whether capturing a piece grants an additional roll.
    • generateInitialGameState

      public abstract GameState generateInitialGameState()
      Generates the initial state for a game.
      Returns:
      The initial state for a game.
    • findAvailableMoves

      public abstract List<Move> findAvailableMoves(Board board, PlayerState player, Roll roll)
      Finds all available moves from the given state.
      Parameters:
      board - The current state of the board.
      player - The current state of the player.
      roll - The roll that was made. Must be non-zero.
      Returns:
      A list of all the available moves from the given state.
    • applyRoll

      public abstract List<GameState> applyRoll(WaitingForRollGameState state, long timeSinceGameStartMs, Roll roll)
      Applies roll to state to generate the new state of the game. Multiple game states may be returned to include information game states for maintaining history. However, the latest or highest-index game state will represent the state of the game after the roll was made.
      Parameters:
      state - The current state of the game.
      timeSinceGameStartMs - The time that this roll took place, measured relative to the start of the game.
      roll - The roll that the player made.
      Returns:
      A list of new game states after the given move was made. The list may include historical information game states, and will always include the new state of the game as its last element.
    • applyMove

      public abstract List<GameState> applyMove(WaitingForMoveGameState state, long timeSinceGameStartMs, Move move)
      Applies move to state to generate the new state of the game. Multiple game states may be returned to include information game states for maintaining history. However, the latest or highest-index game state will represent the state of the game after the move was made.

      This method does not check that the given move is valid.

      Parameters:
      state - The current state of the game.
      timeSinceGameStartMs - The time that this roll took place, measured relative to the start of the game.
      move - The move that the player chose to make from this position.
      Returns:
      A list of new game states after the given move was made. The list may include historical information game states, and will always include the new state of the game as its last element.
    • applyResign

      public List<GameState> applyResign(GameState state, long timeSinceGameStartMs, PlayerType player)
      Applies a resignation by player to generate the new state of the game.
      Parameters:
      state - The current state of the game.
      timeSinceGameStartMs - The time that this roll took place, measured relative to the start of the game.
      player - The player that resigned the game.
      Returns:
      A list of game states representing the resignation and the end of the game.
    • applyAbandon

      public List<GameState> applyAbandon(GameState state, long timeSinceGameStartMs, AbandonReason reason, @Nullable PlayerType player)
      Applies an abandonment of the game due to reason. If the abandonment was caused by a player, then player should be provided.
      Parameters:
      state - The current state of the game.
      timeSinceGameStartMs - The time that this roll took place, measured relative to the start of the game.
      reason - The reason that the game was abandoned.
      player - The player that abandoned the game, or null.
      Returns:
      A list of game states representing the resignation and the end of the game.
    • selectLandmarkStates

      public abstract List<GameState> selectLandmarkStates(List<GameState> states)
      Selects only the states that are required to reproduce exactly what happened in a game using this rule set. This is used to reduce the amount of information saved during serialisation.
      Parameters:
      states - All the states in a game.
    • createSimple

      public static SimpleRuleSet createSimple(GameSettings settings)
      Creates a simple rule set that follows the given game settings.