View source: R/is_repetition.R
is_repetition | R Documentation |
This function checks if a position has occurred n times in a list of
chessboards. See fen_to_board()
for details of the board format.
The repetition of a position is determined as described in
The FIDE Laws of Chess, Section 9.2.
That is, positions are considered to be repeated only if the pieces are on
the same squares, the same side has the move, castling rights are the same,
and en passant rights are the same.
is_repetition(board_list, n)
board_list |
A list of chess boards. |
n |
The number of repetitions to check for. |
TRUE if any position is repeated n times, FALSE otherwise.
# Repeat positions by moving knights back and forth
boards <- list(fen_to_board()) # starting position
boards[[2]] <- update_board('g1f3', boards[[1]])
boards[[3]] <- update_board('g8f6', boards[[2]])
boards[[4]] <- update_board('f3g1', boards[[3]])
boards[[5]] <- update_board('f6g8', boards[[4]]) # back to starting position
is_repetition(boards, 3)
boards[[6]] <- update_board('g1f3', boards[[5]])
boards[[7]] <- update_board('g8f6', boards[[6]])
boards[[8]] <- update_board('f3g1', boards[[7]])
boards[[9]] <- update_board('f6g8', boards[[8]]) # back to starting position
is_repetition(boards, 3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.