GameUtils

object GameUtils

Utility functions for chess game logic, including move application, check detection, attack detection, and insufficient material checks.

Overview

  • Provides methods for applying moves, detecting checks, evaluating attacks, and determining insufficient material.

  • Designed to work with the chessboard and game state objects.

Move Application

  • makeMove: Applies a move to the board and updates the game state.

Check Detection

  • isKingInCheck: Determines if the king of a given color is in check.

Attack Detection

  • isSquareAttackedBy: Checks if a square is attacked by pieces of a specific color.

Material Evaluation

  • hasInsufficientMaterial: Determines if the board position has insufficient material for checkmate.

Example Usage

val newState = GameUtils.makeMove(board, gameState, move)
val isCheck = GameUtils.isKingInCheck(PieceColor.WHITE, board)
val isAttacked = GameUtils.isSquareAttackedBy(square, PieceColor.BLACK, board)
val insufficientMaterial = GameUtils.hasInsufficientMaterial(board)

Functions

Link copied to clipboard

Checks if the given board position has insufficient material for either player to checkmate.

Link copied to clipboard
fun isKingInCheck(kingColor: PieceColor, board: Board): Boolean

Checks if the king of the given kingColor is in check on the board.

Link copied to clipboard
fun isSquareAttackedBy(square: Square, attackerColor: PieceColor, board: Board): Boolean

Determines if a square is attacked by any piece of attackerColor on the board.

Link copied to clipboard
fun makeMove(board: Board, gameState: GameState, move: Move): Pair<Board, GameState>

Applies a move to the given board and gameState, returning the new board and game state.