Class RGN

java.lang.Object
net.royalur.notation.RGN
All Implemented Interfaces:
Notation

public class RGN extends Object implements Notation
RGN (Royal Game Notation) is a textual format to encode games of the Royal Game of Ur. The notation is intended to be readable by both humans and machines. This notation is inspired by Chess' PGN (Portable Game Notation).

RGN was developed by Padraig Lamont with help from several contributors from the Royal Game of Ur Discord server: Airis, Diego Raposo, Monomino, Sachertorte, Capt. Fab., and Raph.

  • Field Details

    • DEFAULT_MAX_ACTION_LINE_LENGTH

      public static final int DEFAULT_MAX_ACTION_LINE_LENGTH
      The default maximum length for lines in RGN that encode the actions taken in a game.
      See Also:
    • DEFAULT_MAX_TURN_LINE_LENGTH

      public static final int DEFAULT_MAX_TURN_LINE_LENGTH
      The default maximum length of each line representing a turn in RGN. A single turn can exceed the max action line length, in which case it will be placed on its own line.
      See Also:
  • Constructor Details

    • RGN

      public RGN(Map<String,? extends PathPairFactory> pathPairs, Map<String,? extends BoardShapeFactory> boardShapes, int maxActionLineLength, int maxTurnLineLength)
      Instantiates the RGN 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.
      maxActionLineLength - The maximum length of the lines that contain moves.
      maxTurnLineLength - The maximum length of a turn before it is split onto another line.
    • RGN

      public RGN()
      Instantiates the RGN notation to encode and decode games.
  • Method Details

    • escape

      public static String escape(String value)
      Escapes value so that it can be included as a metadata value.
      Parameters:
      value - The value to be escaped.
      Returns:
      The escaped version of value.
    • appendDiceRoll

      public void appendDiceRoll(RuleSet rules, StringBuilder builder, RolledGameState rolledState)
      Encodes the dice roll from rolledState into builder.
      Parameters:
      rules - The rules of the game in which the dice are being encoded.
      builder - The builder into which to append the encoded dice roll.
      rolledState - The state of the game that contains the dice roll to encode.
    • appendMove

      public void appendMove(RuleSet rules, StringBuilder builder, Move move)
      Encodes the move from movedState into builder.
      Parameters:
      rules - The rules of the game in which the dice are being encoded.
      builder - The builder into which to append the encoded move.
      move - The move to encode.
    • appendMove

      public void appendMove(RuleSet rules, StringBuilder builder, Move move, boolean spaceBeforeRosette)
      Encodes the move from movedState into builder.
      Parameters:
      rules - The rules of the game in which the dice are being encoded.
      builder - The builder into which to append the encoded move.
      move - The move to encode.
      spaceBeforeRosette - Whether to include a space before the asterisk used to indicate landing on a rosette.
    • encodeGame

      public String encodeGame(Game game)
      Description copied from interface: Notation
      Encodes the given game, game, into text.
      Specified by:
      encodeGame in interface Notation
      Parameters:
      game - The game to be encoded.
      Returns:
      Text that represents game in this notation.
    • decodeGame

      public Game decodeGame(String encoded)
      Description copied from interface: Notation
      Decodes the game from the text encoded, based upon the rules rules.
      Specified by:
      decodeGame in interface Notation
      Parameters:
      encoded - The text to decode into a game.
      Returns:
      The decoded game.