Package net.royalur.rules
Class RuleSet
java.lang.Object
net.royalur.rules.RuleSet
- Direct Known Subclasses:
SimpleRuleSet
A set of rules that govern the play of a game of the Royal Game of Ur.
-
Field Summary
Modifier and TypeFieldDescriptionprotected final BoardShape
The shape of the game board.protected final DiceFactory
The generator of dice that are used to generate dice rolls.protected final PathPair
The paths that each player must take around the board.protected final PieceProvider
Provides the manipulation of piece values.protected final PlayerStateProvider
Provides the manipulation of player state values.protected final Dice
A sample dice that can be used for parsing, but should not be used for running games. -
Constructor Summary
ModifierConstructorDescriptionprotected
RuleSet
(BoardShape boardShape, PathPair paths, DiceFactory diceFactory, PieceProvider pieceProvider, PlayerStateProvider playerStateProvider) Instantiates a rule set for the Royal Game of Ur. -
Method Summary
Modifier and TypeMethodDescriptionapplyAbandon
(GameState state, long timeSinceGameStartMs, AbandonReason reason, PlayerType player) Applies an abandonment of the game due toreason
.applyMove
(WaitingForMoveGameState state, long timeSinceGameStartMs, Move move) Appliesmove
tostate
to generate the new state of the game.applyResign
(GameState state, long timeSinceGameStartMs, PlayerType player) Applies a resignation byplayer
to generate the new state of the game.applyRoll
(WaitingForRollGameState state, long timeSinceGameStartMs, Roll roll) Appliesroll
tostate
to generate the new state of the game.abstract boolean
Gets whether rosettes are considered safe squares in this rule set.static SimpleRuleSet
createSimple
(GameSettings settings) Creates a simple rule set that follows the given game settings.abstract boolean
Gets whether capturing a piece grants an additional roll.abstract boolean
Gets whether landing on rosette tiles grants an additional roll.findAvailableMoves
(Board board, PlayerState player, Roll roll) Finds all available moves from the given state.abstract GameState
Generates the initial state for a game.Gets the shape of the board used in this rule set.Gets the generator of dice that are used to generate dice rolls.getPaths()
Gets the paths that the players must take around the board.Gets the provider of piece manipulations.Gets the provider of player state manipulations.Gets a sample dice that can be used for parsing, but should not be used for running games.Get the settings used for this rule set.selectLandmarkStates
(List<GameState> states) Selects only the states that are required to reproduce exactly what happened in a game using this rule set.
-
Field Details
-
boardShape
The shape of the game board. -
paths
The paths that each player must take around the board. -
diceFactory
The generator of dice that are used to generate dice rolls. -
sampleDice
A sample dice that can be used for parsing, but should not be used for running games. -
pieceProvider
Provides the manipulation of piece values. -
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
Get the settings used for this rule set.- Returns:
- The settings used for this rule set.
-
getBoardShape
Gets the shape of the board used in this rule set.- Returns:
- The shape of the game board.
-
getPaths
Gets the paths that the players must take around the board.- Returns:
- The paths that players must take around the board.
-
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
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
Gets the provider of piece manipulations.- Returns:
- The provider of making piece changes.
-
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
Generates the initial state for a game.- Returns:
- The initial state for a game.
-
findAvailableMoves
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) Appliesroll
tostate
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) Appliesmove
tostate
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
Applies a resignation byplayer
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 toreason
. If the abandonment was caused by a player, thenplayer
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, ornull
.- Returns:
- A list of game states representing the resignation and the end of the game.
-
selectLandmarkStates
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
Creates a simple rule set that follows the given game settings.
-