can_rook_move: Check if a rook has any legal moves

View source: R/can_rook_move.R

can_rook_moveR Documentation

Check if a rook has any legal moves

Description

This function checks if a rook at a given position on a chess board has any legal moves.

Usage

can_rook_move(board, coordinates, color = board$to_move)

rook_can_move(board, coordinates, color = board$to_move)

Arguments

board

A list containing the current state of the chess board.

coordinates

A vector of length 2 representing the coordinates of the rook on the board. The first element is the row number and the second element is the column number.

color

An optional character vector giving the color of the rook. Defaults to the color of the player whose turn it is to move.

Details

See fen_to_board() for details of the chess board format. This function is used by other functions when testing for stalemate. can_rook_move() is an alias for rook_can_move().

Value

A logical value indicating whether the rook has any legal moves (TRUE) or not (FALSE).

Examples

board <- fen_to_board() # Starting position
coordinates <- c(1, 1)  # Coordinates of the white rook in the starting position
can_rook_move(board, coordinates)

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