GameLogic

internal object GameLogic

Contains the core game logic for Reversi, including methods to play a piece, check for valid moves, and find capturable pieces.

Functions

Link copied to clipboard
fun findAround(board: Board, myPiece: Piece, findThis: PieceType?): List<Coordinate>

Finds all coordinates with 1 cell distance from the given piece that contain the specified type of piece.

Link copied to clipboard
fun getAvailablePlays(board: Board, myPieceType: PieceType): List<Coordinate>

Gets a list of available plays for the player with the specified piece type. A play is considered available if placing a piece of the given type at that position would result in capturing at least one of the opponent's pieces.

Link copied to clipboard
fun getCapturablePieces(board: Board, myPiece: Piece, direction: Coordinate): List<Coordinate>

Gets a list of capturable pieces in a specified direction from the given piece. A piece is considered capturable if it is of the opposite type and is followed by a piece of the same type as myPiece in the specified direction.

Link copied to clipboard
fun isValidMove(board: Board, myPiece: Piece): Boolean

Checks if placing a piece at the specified coordinates is a valid move. A move is considered valid if it results in capturing at least one of the opponent's pieces.

Link copied to clipboard
fun play(board: Board, myPiece: Piece): Board

Plays a piece on the board and returns the new state of the board. The play is valid if it captures at least one of the opponent's pieces.