Class GameState

java.lang.Object
net.royalur.rules.state.GameState
Direct Known Subclasses:
ControlGameState, EndGameState, OngoingGameState

public abstract class GameState extends Object
A game state represents a single point within a game.
  • Constructor Details

    • GameState

      public GameState(Board board, PlayerState lightPlayer, PlayerState darkPlayer, long timeSinceGameStartMs)
      Instantiates a game state.
      Parameters:
      board - The state of the pieces on the board.
      lightPlayer - The state of the light player.
      darkPlayer - The state of the dark player.
      timeSinceGameStartMs - The time this state was created.
  • Method Details

    • getBoard

      public Board getBoard()
      Get the state of the pieces on the board.
      Returns:
      The state of the pieces on the board.
    • getLightPlayer

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

      public PlayerState getDarkPlayer()
      Get the state of the dark player.
      Returns:
      The state of the dark player.
    • getPlayerState

      public PlayerState getPlayerState(PlayerType player)
      Gets the state of the player player.
      Parameters:
      player - The player to retrieve the state of.
      Returns:
      The state of the player player.
    • getTimeSinceGameStartMs

      public long getTimeSinceGameStartMs()
      Gets the time this state was created, measured by the number of milliseconds elapsed since the start of the game.
      Returns:
      The time this state was created.
    • addMetadata

      public void addMetadata(String key, String value)
      Add a piece of metadata to this state.
      Parameters:
      key - The identifier for the metadata to add.
      value - The value associated with the key.
    • addMetadata

      public void addMetadata(Map<String,String> entries)
      Adds many pieces of metadata to this state.
      Parameters:
      entries - The pieces of metadata to add.
    • removeMetadata

      public String removeMetadata(String key)
      Removes a piece of metadata from this state.
      Parameters:
      key - The identifier for the metadata to remove.
      Returns:
      The value that was associated with the key, or null if none existed.
    • clearMetadata

      public void clearMetadata()
      Removes all metadata from this state.
    • hasMetadata

      public boolean hasMetadata(String key)
      Checks whether this state has metadata associated with the given key.
      Parameters:
      key - The identifier to check for.
      Returns:
      Whether the key exists in the metadata.
    • getMetadata

      public String getMetadata(String key)
      Retrieves the value of a specific metadata entry.
      Parameters:
      key - The identifier of the metadata to retrieve.
      Returns:
      The value associated with the key, or null if none exists.
    • getMetadata

      public Map<String,String> getMetadata()
      Gets the metadata associated with this state.
      Returns:
      The metadata associated with this state.
    • getSubject

      @Nullable public abstract PlayerType getSubject()
      Get the subject player of the game state. e.g., player to roll/move, player that rolled/moved, player that won.
    • isPlayable

      public abstract boolean isPlayable()
      Returns whether this state is a valid state to be played from.
      Returns:
      Whether this state is a valid state to be played from.
    • isFinished

      public abstract boolean isFinished()
      Returns whether this state represents a finished game.
      Returns:
      Whether this state represents a finished game.
    • describe

      public abstract String describe()
      Generates an English text description of the state of the game.
      Returns:
      An English text description of the state of the game.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object