Package net.royalur.notation
Class JsonNotation
java.lang.Object
net.royalur.notation.JsonNotation
- All Implemented Interfaces:
Notation
A notation that can be used to encode games of the Royal
Game of Ur into JSON for serialisation. This notation
has been created to be read by machines, not humans.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The key in the JSON for the reason that a game was abandoned.static final String
The key in the JSON for the moves that are available in a state.static final String
The key in the JSON for the state of the board.static final String
The key in the JSON for the pieces on a board.static final String
The key in the JSON for the game setting of the board shape used.static final String
The key in the JSON for the game setting of whether rosettes grant extra rolls.static final String
The key in the JSON for the player that abandoned the game.static final String
The key in the JSON for the game settings of the dice used.static final String
The key in the JSON for the initial state of the board and players.static final int
The latest version of the JSON notation.static final String
The key in the JSON for the metadata of the game.static final String
The key in the JSON for the captured piece of a move.static final String
The key in the JSON for the destination piece of a move.static final String
The key in the JSON for a move that was made.static final String
The key in the JSON for the source piece of a move.static final String
The old key in the JSON for the index of a piece on its path.static final String
The old key in the JSON for the owner of a piece.static final String
The key in the JSON for the game setting of the paths used.static final String
The key in the JSON for the pieces of a player state.static final String
The key in the JSON for the score of a player state.static final String
The key in the JSON for the state of the players.static final String
The key in the JSON for the roll that was made.static final String
The key in the JSON for the value of a roll.static final String
The key in the JSON for the game setting of whether rosettes grant extra rolls.static final String
The key in the JSON for the game setting of whether rosettes are safe.static final String
The key in the JSON for the settings of a game.static final String
The key in the JSON for game setting of the starting piece count.static final String
The key in the JSON for the time this state was reached in milliseconds since the start of the game.static final String
Represents states of typeAbandonedGameState
.static final String
Represents states of typeEndGameState
.static final String
The key in the JSON for the type of state.static final String
Represents states of typeMovedGameState
.static final String
Represents states of typeResignedGameState
.static final String
Represents states of typeRolledGameState
.static final String
Represents states of typeWaitingForMoveGameState
.static final String
Represents states of typeWaitingForRollGameState
.static final String
The key in the JSON for the list of states in the game.static final String
The key in the JSON for the player whose turn it is in a state.static final String
The key in the JSON for the version of the notation.static final String
The key in the JSON for the player that won the game. -
Constructor Summary
ConstructorDescriptionInstantiates a default JSON notation to read simple games.JsonNotation
(Map<String, ? extends BoardShapeFactory> boardShapes, Map<String, ? extends PathPairFactory> pathPairs, Map<String, ? extends DiceFactory> dice, RuleSetProvider ruleSetProvider) Instantiates the JSON notation to encode and decode games.JsonNotation
(Map<String, ? extends BoardShapeFactory> boardShapes, Map<String, ? extends PathPairFactory> pathPairs, Map<String, ? extends DiceFactory> dice, RuleSetProvider ruleSetProvider, com.fasterxml.jackson.core.JsonFactory jsonFactory) Instantiates the JSON notation to encode and decode games. -
Method Summary
Modifier and TypeMethodDescriptiondecodeGame
(String encoded) Decodes the game from the textencoded
, based upon the rulesrules
.encodeGame
(Game game) Encodes the given game,game
, into text.int
encodePiece
(Piece piece) com.fasterxml.jackson.core.JsonFactory
com.fasterxml.jackson.databind.ObjectMapper
getStateType
(GameState state) boolean
isActionState
(String stateType) boolean
isControlState
(String stateType) boolean
isOngoingState
(String stateType) boolean
isPlayableState
(String stateType) readAbandonedState
(RuleSet rules, long timeSinceGameStartMs, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json, PlayerType player) readActionState
(RuleSet rules, long timeSinceGameStartMs, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json, String stateType, PlayerType turn) readCompleteState
(RuleSet rules, com.fasterxml.jackson.databind.node.ObjectNode json) readControlState
(RuleSet rules, long timeSinceGameStartMs, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json, String stateType) readDerivedState
(RuleSet rules, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json) readEndState
(RuleSet rules, long timeSinceGameStartMs, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json) readGame
(com.fasterxml.jackson.databind.node.ObjectNode json) readGameSettings
(com.fasterxml.jackson.databind.node.ObjectNode json) readGameV1Or2
(com.fasterxml.jackson.databind.node.ObjectNode json) readMetadata
(com.fasterxml.jackson.databind.node.ObjectNode json) readMovedState
(RuleSet rules, long timeSinceGameStartMs, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json, PlayerType turn) readMoveList
(RuleSet rules, com.fasterxml.jackson.databind.node.ArrayNode json) readNullablePiece
(RuleSet rules, com.fasterxml.jackson.databind.node.ObjectNode json, String key) readOldPiece
(RuleSet rules, com.fasterxml.jackson.databind.node.ObjectNode json) readOngoingState
(RuleSet rules, long timeSinceGameStartMs, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json, String stateType) readPlayableState
(RuleSet rules, long timeSinceGameStartMs, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json, String stateType, PlayerType turn) readPlayerState
(RuleSet rules, PlayerType playerType, com.fasterxml.jackson.databind.node.ObjectNode json) readResignedState
(RuleSet rules, long timeSinceGameStartMs, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json, PlayerType player) readRolledState
(RuleSet rules, long timeSinceGameStartMs, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json, PlayerType turn) readStates
(RuleSet rules, GameState initialState, com.fasterxml.jackson.databind.node.ArrayNode json) readWaitingForMoveState
(RuleSet rules, long timeSinceGameStartMs, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json, PlayerType turn) readWaitingForRollState
(RuleSet rules, long timeSinceGameStartMs, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json, PlayerType turn) void
writeAbandonedState
(com.fasterxml.jackson.core.JsonGenerator generator, AbandonedGameState state) void
writeActionState
(com.fasterxml.jackson.core.JsonGenerator generator, ActionGameState state) void
writeBoard
(com.fasterxml.jackson.core.JsonGenerator generator, Board board) void
writeCompleteState
(com.fasterxml.jackson.core.JsonGenerator generator, GameState state) void
writeControlState
(com.fasterxml.jackson.core.JsonGenerator generator, ControlGameState state) void
writeDerivedState
(com.fasterxml.jackson.core.JsonGenerator generator, GameState state) void
writeEndState
(com.fasterxml.jackson.core.JsonGenerator generator, EndGameState state) void
void
writeGameSettings
(com.fasterxml.jackson.core.JsonGenerator generator, GameSettings settings) void
writeMetadata
(com.fasterxml.jackson.core.JsonGenerator generator, GameMetadata metadata) void
void
writeMovedState
(com.fasterxml.jackson.core.JsonGenerator generator, MovedGameState state) void
writeMoveList
(com.fasterxml.jackson.core.JsonGenerator generator, List<Move> moves) void
writeOngoingState
(com.fasterxml.jackson.core.JsonGenerator generator, OngoingGameState state) protected void
writePieceField
(com.fasterxml.jackson.core.JsonGenerator generator, String fieldName, Piece piece) void
writePlayableState
(com.fasterxml.jackson.core.JsonGenerator generator, PlayableGameState state) void
writePlayerState
(com.fasterxml.jackson.core.JsonGenerator generator, PlayerState playerState) void
writeResignedState
(com.fasterxml.jackson.core.JsonGenerator generator, ResignedGameState state) void
void
writeRolledState
(com.fasterxml.jackson.core.JsonGenerator generator, RolledGameState state) void
writeStates
(com.fasterxml.jackson.core.JsonGenerator generator, List<GameState> states) void
writeWaitingForMoveState
(com.fasterxml.jackson.core.JsonGenerator generator, WaitingForMoveGameState state) void
writeWaitingForRollState
(com.fasterxml.jackson.core.JsonGenerator generator, WaitingForRollGameState state)
-
Field Details
-
LATEST_VERSION
public static final int LATEST_VERSIONThe latest version of the JSON notation. If any breaking changes are made to the JSON notation, then this field will be updated to reflect that.- See Also:
-
VERSION_KEY
The key in the JSON for the version of the notation.- See Also:
-
METADATA_KEY
The key in the JSON for the metadata of the game.- See Also:
-
SETTINGS_KEY
The key in the JSON for the settings of a game.- See Also:
-
BOARD_SHAPE_KEY
The key in the JSON for the game setting of the board shape used.- See Also:
-
PATHS_KEY
The key in the JSON for the game setting of the paths used.- See Also:
-
DICE_KEY
The key in the JSON for the game settings of the dice used.- See Also:
-
STARTING_PIECE_COUNT_KEY
The key in the JSON for game setting of the starting piece count.- See Also:
-
SAFE_ROSETTES_KEY
The key in the JSON for the game setting of whether rosettes are safe.- See Also:
-
ROSETTES_GRANT_EXTRA_ROLLS_KEY
The key in the JSON for the game setting of whether rosettes grant extra rolls.- See Also:
-
CAPTURES_GRANT_EXTRA_ROLLS_KEY
The key in the JSON for the game setting of whether rosettes grant extra rolls.- See Also:
-
INITIAL_STATE_KEY
The key in the JSON for the initial state of the board and players.- See Also:
-
STATES_KEY
The key in the JSON for the list of states in the game.- See Also:
-
STATE_TYPE_KEY
The key in the JSON for the type of state.- See Also:
-
STATE_TIME_KEY
The key in the JSON for the time this state was reached in milliseconds since the start of the game.- See Also:
-
STATE_TYPE_ROLLED
Represents states of typeRolledGameState
.- See Also:
-
STATE_TYPE_MOVED
Represents states of typeMovedGameState
.- See Also:
-
STATE_TYPE_WAITING_FOR_ROLL
Represents states of typeWaitingForRollGameState
.- See Also:
-
STATE_TYPE_WAITING_FOR_MOVE
Represents states of typeWaitingForMoveGameState
.- See Also:
-
STATE_TYPE_RESIGNED
Represents states of typeResignedGameState
.- See Also:
-
STATE_TYPE_ABANDONED
Represents states of typeAbandonedGameState
.- See Also:
-
STATE_TYPE_END
Represents states of typeEndGameState
.- See Also:
-
ROLL_KEY
The key in the JSON for the roll that was made.- See Also:
-
ROLL_VALUE_KEY
The key in the JSON for the value of a roll.- See Also:
-
MOVE_KEY
The key in the JSON for a move that was made.- See Also:
-
MOVE_SOURCE_KEY
The key in the JSON for the source piece of a move.- See Also:
-
MOVE_DEST_KEY
The key in the JSON for the destination piece of a move.- See Also:
-
MOVE_CAPTURED_KEY
The key in the JSON for the captured piece of a move.- See Also:
-
AVAILABLE_MOVES_KEY
The key in the JSON for the moves that are available in a state.- See Also:
-
OLD_PIECE_OWNER_KEY
The old key in the JSON for the owner of a piece.- See Also:
-
OLD_PIECE_INDEX_KEY
The old key in the JSON for the index of a piece on its path.- See Also:
-
TURN_KEY
The key in the JSON for the player whose turn it is in a state.- See Also:
-
CONTROL_PLAYER_KEY
The key in the JSON for the player that abandoned the game.- See Also:
-
ABANDONED_REASON_KEY
The key in the JSON for the reason that a game was abandoned.- See Also:
-
WINNER_KEY
The key in the JSON for the player that won the game.- See Also:
-
BOARD_KEY
The key in the JSON for the state of the board.- See Also:
-
BOARD_PIECES_KEY
The key in the JSON for the pieces on a board.- See Also:
-
PLAYERS_KEY
The key in the JSON for the state of the players.- See Also:
-
PLAYER_PIECES_KEY
The key in the JSON for the pieces of a player state.- See Also:
-
PLAYER_SCORE_KEY
The key in the JSON for the score of a player state.- See Also:
-
-
Constructor Details
-
JsonNotation
public JsonNotation(Map<String, ? extends BoardShapeFactory> boardShapes, Map<String, ? extends PathPairFactory> pathPairs, Map<String, ? extends DiceFactory> dice, RuleSetProvider ruleSetProvider, com.fasterxml.jackson.core.JsonFactory jsonFactory) Instantiates the JSON notation to encode and decode games.- Parameters:
pathPairs
- The paths that can be parsed in this notation.boardShapes
- The board shapes that can be parsed in this notation.dice
- The dice that can be parsed in this notation.ruleSetProvider
- The provider to create rule sets from game settings.jsonFactory
- A factory to build generators to write the JSON.
-
JsonNotation
public JsonNotation(Map<String, ? extends BoardShapeFactory> boardShapes, Map<String, ? extends PathPairFactory> pathPairs, Map<String, ? extends DiceFactory> dice, RuleSetProvider ruleSetProvider) Instantiates the JSON notation to encode and decode games.- Parameters:
pathPairs
- The paths that can be parsed in this notation.boardShapes
- The board shapes that can be parsed in this notation.dice
- The dice that can be parsed in this notation.ruleSetProvider
- The provider to create rule sets from game settings.
-
JsonNotation
public JsonNotation()Instantiates a default JSON notation to read simple games.
-
-
Method Details
-
getJsonFactory
public com.fasterxml.jackson.core.JsonFactory getJsonFactory() -
getObjectMapper
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper() -
writeRoll
public void writeRoll(com.fasterxml.jackson.core.JsonGenerator generator, Roll roll) throws IOException - Throws:
IOException
-
encodePiece
-
writePieceField
protected void writePieceField(com.fasterxml.jackson.core.JsonGenerator generator, String fieldName, @Nullable Piece piece) throws IOException - Throws:
IOException
-
writeMove
public void writeMove(com.fasterxml.jackson.core.JsonGenerator generator, Move move) throws IOException - Throws:
IOException
-
writeMoveList
public void writeMoveList(com.fasterxml.jackson.core.JsonGenerator generator, List<Move> moves) throws IOException - Throws:
IOException
-
writeBoard
public void writeBoard(com.fasterxml.jackson.core.JsonGenerator generator, Board board) throws IOException - Throws:
IOException
-
writePlayerState
public void writePlayerState(com.fasterxml.jackson.core.JsonGenerator generator, PlayerState playerState) throws IOException - Throws:
IOException
-
writeRolledState
public void writeRolledState(com.fasterxml.jackson.core.JsonGenerator generator, RolledGameState state) throws IOException - Throws:
IOException
-
writeMovedState
public void writeMovedState(com.fasterxml.jackson.core.JsonGenerator generator, MovedGameState state) throws IOException - Throws:
IOException
-
writeActionState
public void writeActionState(com.fasterxml.jackson.core.JsonGenerator generator, ActionGameState state) throws IOException - Throws:
IOException
-
writeWaitingForRollState
public void writeWaitingForRollState(com.fasterxml.jackson.core.JsonGenerator generator, WaitingForRollGameState state) -
writeWaitingForMoveState
public void writeWaitingForMoveState(com.fasterxml.jackson.core.JsonGenerator generator, WaitingForMoveGameState state) throws IOException - Throws:
IOException
-
writePlayableState
public void writePlayableState(com.fasterxml.jackson.core.JsonGenerator generator, PlayableGameState state) throws IOException - Throws:
IOException
-
writeOngoingState
public void writeOngoingState(com.fasterxml.jackson.core.JsonGenerator generator, OngoingGameState state) throws IOException - Throws:
IOException
-
writeResignedState
public void writeResignedState(com.fasterxml.jackson.core.JsonGenerator generator, ResignedGameState state) throws IOException - Throws:
IOException
-
writeAbandonedState
public void writeAbandonedState(com.fasterxml.jackson.core.JsonGenerator generator, AbandonedGameState state) throws IOException - Throws:
IOException
-
writeControlState
public void writeControlState(com.fasterxml.jackson.core.JsonGenerator generator, ControlGameState state) throws IOException - Throws:
IOException
-
writeEndState
public void writeEndState(com.fasterxml.jackson.core.JsonGenerator generator, EndGameState state) throws IOException - Throws:
IOException
-
getStateType
-
writeDerivedState
public void writeDerivedState(com.fasterxml.jackson.core.JsonGenerator generator, GameState state) throws IOException - Throws:
IOException
-
writeStates
public void writeStates(com.fasterxml.jackson.core.JsonGenerator generator, List<GameState> states) throws IOException - Throws:
IOException
-
writeCompleteState
public void writeCompleteState(com.fasterxml.jackson.core.JsonGenerator generator, GameState state) throws IOException - Throws:
IOException
-
writeGameSettings
public void writeGameSettings(com.fasterxml.jackson.core.JsonGenerator generator, GameSettings settings) throws IOException - Throws:
IOException
-
writeMetadata
public void writeMetadata(com.fasterxml.jackson.core.JsonGenerator generator, GameMetadata metadata) throws IOException - Throws:
IOException
-
writeGame
public void writeGame(com.fasterxml.jackson.core.JsonGenerator generator, Game game) throws IOException - Throws:
IOException
-
encodeGame
Description copied from interface:Notation
Encodes the given game,game
, into text.- Specified by:
encodeGame
in interfaceNotation
- Parameters:
game
- The game to be encoded.- Returns:
- Text that represents
game
in this notation.
-
readRoll
-
readOldPiece
-
readNullablePiece
-
readPiece
-
readMove
-
readMoveList
-
readBoard
-
readPlayerState
public PlayerState readPlayerState(RuleSet rules, PlayerType playerType, com.fasterxml.jackson.databind.node.ObjectNode json) -
isActionState
-
isPlayableState
-
isOngoingState
-
isControlState
-
readRolledState
public RolledGameState readRolledState(RuleSet rules, long timeSinceGameStartMs, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json, PlayerType turn) -
readMovedState
public MovedGameState readMovedState(RuleSet rules, long timeSinceGameStartMs, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json, PlayerType turn) -
readWaitingForRollState
public WaitingForRollGameState readWaitingForRollState(RuleSet rules, long timeSinceGameStartMs, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json, PlayerType turn) -
readWaitingForMoveState
public WaitingForMoveGameState readWaitingForMoveState(RuleSet rules, long timeSinceGameStartMs, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json, PlayerType turn) -
readActionState
public ActionGameState readActionState(RuleSet rules, long timeSinceGameStartMs, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json, String stateType, PlayerType turn) -
readPlayableState
public PlayableGameState readPlayableState(RuleSet rules, long timeSinceGameStartMs, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json, String stateType, PlayerType turn) -
readOngoingState
public OngoingGameState readOngoingState(RuleSet rules, long timeSinceGameStartMs, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json, String stateType) -
readResignedState
public ResignedGameState readResignedState(RuleSet rules, long timeSinceGameStartMs, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json, PlayerType player) -
readAbandonedState
public AbandonedGameState readAbandonedState(RuleSet rules, long timeSinceGameStartMs, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json, @Nullable PlayerType player) -
readControlState
public ControlGameState readControlState(RuleSet rules, long timeSinceGameStartMs, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json, String stateType) -
readEndState
public EndGameState readEndState(RuleSet rules, long timeSinceGameStartMs, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json) -
readDerivedState
public GameState readDerivedState(RuleSet rules, StateSource stateSource, com.fasterxml.jackson.databind.node.ObjectNode json) -
readCompleteState
-
readStates
-
readGameSettings
-
readMetadata
-
readGameV1Or2
-
readGame
-
decodeGame
Description copied from interface:Notation
Decodes the game from the textencoded
, based upon the rulesrules
.- Specified by:
decodeGame
in interfaceNotation
- Parameters:
encoded
- The text to decode into a game.- Returns:
- The decoded game.
-