Interface GameBoard

All Superinterfaces:
JsonSerializable
All Known Implementing Classes:
GameBoardLocalImpl

public interface GameBoard extends JsonSerializable
Represents a game board for a game. The game board has a square dimension and contains a grid of game pieces. This interface defines the operations that can be performed on the game board.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final System.Logger
     
    static final AtomicBoolean
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Converts the game board to a JSON string representation for serialization.
    default List<Integer>
    Returns a list of available moves on the game board.
     
    int
    Returns the dimension of the game board, which is the number of rows or columns.
    boolean
    hasChain(String playerMarker)
    Checks if the given player has a winning chain of connected game pieces on the game board.
    boolean
    Checks if there are any available moves on the game board.
    boolean
    hasPlayer(String playerMarker, int location)
    Checks if the given player is present at the given location on the game board.
    default boolean
     
    boolean
    isValidMove(int location)
    Checks if the given location on the game board is a valid move (i.e.
    Returns a string representation of the game board for presentation to the player.
    static GameBoard
    withDimension(int dimension)
    Creates a new GameBoard instance with the given dimension.
    withMove(String playerMarker, int location)
    Creates a new GameBoard instance with the given player's move made at the specified location within the game board dimension x dimension
  • Field Details

  • Method Details

    • isValidMove

      boolean isValidMove(int location)
      Checks if the given location on the game board is a valid move (i.e. an available location).
      Parameters:
      location - the location on the game board to check
      Returns:
      true if the location is a valid move, false otherwise
    • availableMoves

      default List<Integer> availableMoves()
      Returns a list of available moves on the game board.
      Returns:
      a list of available moves on the game board
    • isEmpty

      default boolean isEmpty()
    • hasPlayer

      boolean hasPlayer(String playerMarker, int location)
      Checks if the given player is present at the given location on the game board.
      Parameters:
      playerMarker - the marker representing the player to check
      location - the location on the game board to check
      Returns:
      true if the player is present at the given location, false otherwise
    • hasChain

      boolean hasChain(String playerMarker)
      Checks if the given player has a winning chain of connected game pieces on the game board.
      Parameters:
      playerMarker - the marker representing the player to check for a chain
      Returns:
      true if the player has a chain of connected game pieces, false otherwise
    • hasMovesAvailable

      boolean hasMovesAvailable()
      Checks if there are any available moves on the game board.
      Returns:
      true if there are any available moves, false otherwise
    • withMove

      GameBoard withMove(String playerMarker, int location)
      Creates a new GameBoard instance with the given player's move made at the specified location within the game board dimension x dimension
      Parameters:
      playerMarker - the marker representing the player making the move
      location - the location on the game board where the player is making the move
      Returns:
      a ne GameBoard instance with the player's move applied
    • dimension

      int dimension()
      Returns the dimension of the game board, which is the number of rows or columns.
      Returns:
      the dimension of the game board
    • asJsonString

      String asJsonString()

      Converts the game board to a JSON string representation for serialization. Format corresponds to the following JSON schema with content as a 1D array of strings of size dimension x dimension.

      { "dimension": int, "content": [ string, string, ..., string ] } }
      
      Specified by:
      asJsonString in interface JsonSerializable
      Returns:
      the game board as a JSON string
      See Also:
    • toString

      String toString()
      Returns a string representation of the game board for presentation to the player.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the game board.
    • withDimension

      static GameBoard withDimension(int dimension)
      Creates a new GameBoard instance with the given dimension.
      Parameters:
      dimension - the dimension of the game board, which is the number of rows or columns
      Returns:
      a new GameBoard instance with the specified dimension
    • content

      String[] content()