is_stalemate: Check for a stalemate condition in a chess game

View source: R/is_stalemate.R

is_stalemateR Documentation

Check for a stalemate condition in a chess game

Description

This function checks if the current player is in a stalemate condition, which means the player is not in check but has no valid moves.

Usage

is_stalemate(board, color = board$to_move)

Arguments

board

A list containing the game state. The list should have a component named "board" which is an 8x8 matrix representing the game board, and a component named "to_move" which is a string representing the color of the player to move ("white" or "black").

color

The color of the player to check for stalemate. If not provided, the color of the player to move is used.

Value

TRUE if the player is in stalemate, FALSE otherwise.

Examples

board <- fen_to_board() # Starting position
is_stalemate(board)
fen <- "8/8/8/2p2p1p/2P2P1k/4pP1P/4P1KP/5BNR w - - 0 19" # Both players in stalemate
board <- fen_to_board(fen)
is_stalemate(board)
is_stalemate(board, "black")

dryguy/rbitr documentation built on Oct. 15, 2024, 6:18 a.m.