Record Class GameBoardLocalImpl
java.lang.Object
java.lang.Record
org.xxdc.oss.example.GameBoardLocalImpl
- Record Components:
dimension- the dimension of the boardcontent- the current state of the board, represented as a 1D array of player marker strings
- All Implemented Interfaces:
Serializable,GameBoard,JsonSerializable
public record GameBoardLocalImpl(int dimension, String[] content)
extends Record
implements Serializable, GameBoard
Represents a game board for a game, such as tic-tac-toe. The board has a specified dimension, and
stores the current state of the game in a 1D array. Provides methods to check the validity of
moves, place player markers, check for a winner, and get a string representation of the board.
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionGameBoardLocalImpl(int dimension) Constructs a newGameBoardLocalImplinstance with the specified dimension and initializes the content array with null values.GameBoardLocalImpl(int dimension, String[] content) Creates an instance of aGameBoardLocalImplrecord class. -
Method Summary
Modifier and TypeMethodDescriptionConverts the game board to a JSON string representation for serialization.clone()String[]content()Returns the value of thecontentrecord component.intReturns the value of thedimensionrecord component.final booleanIndicates whether some other object is "equal to" this one.booleanChecks if the given player has a winning chain of connected game pieces on the game board.final inthashCode()Returns a hash code value for this object.booleanChecks if there are any available moves on the game board.booleanChecks if the given player is present at the given location on the game board.booleanisValidMove(int location) Checks if the given location on the game board is a valid move (i.e.toString()Returns a string representation of this record class.Creates a newGameBoardinstance with the given player's move made at the specified location within the game board dimension x dimensionMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.xxdc.oss.example.GameBoard
availableMoves, isEmpty
-
Constructor Details
-
GameBoardLocalImpl
public GameBoardLocalImpl(int dimension) Constructs a newGameBoardLocalImplinstance with the specified dimension and initializes the content array with null values.- Parameters:
dimension- the dimension of the game board
-
GameBoardLocalImpl
-
-
Method Details
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
isValidMove
public boolean isValidMove(int location) Description copied from interface:GameBoardChecks if the given location on the game board is a valid move (i.e. an available location).- Specified by:
isValidMovein interfaceGameBoard- Parameters:
location- the location on the game board to check- Returns:
- true if the location is a valid move, false otherwise
-
hasChain
Description copied from interface:GameBoardChecks if the given player has a winning chain of connected game pieces on the game board. -
hasMovesAvailable
public boolean hasMovesAvailable()Description copied from interface:GameBoardChecks if there are any available moves on the game board.- Specified by:
hasMovesAvailablein interfaceGameBoard- Returns:
- true if there are any available moves, false otherwise
-
withMove
-
asJsonString
Description copied from interface:GameBoardConverts 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:
asJsonStringin interfaceGameBoard- Specified by:
asJsonStringin interfaceJsonSerializable- Returns:
- the game board as a JSON string
- See Also:
-
clone
-
hasPlayer
Description copied from interface:GameBoardChecks if the given player is present at the given location on the game board. -
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
dimension
-
content
-