convert_scores: Convert mates and bounds to numeric values

View source: R/convert_scores.R

convert_scoresR Documentation

Convert mates and bounds to numeric values

Description

A function to convert "mate x", "x upperbound", and "x lowerbound" into numeric values (in centipawns).

Usage

convert_scores(scores, mate = 5000, flip_signs = TRUE)

Arguments

scores

A character vector of scores from a UCI compatible chess engine.

mate

(Default = 5000) A single-element integer vector of the value to use for 'mate x'.

flip_signs

(Default = TRUE) A Boolean indicating whether to flip the sign of even numbered half-moves.

Details

UCI compatible chess engines return positional evaluations in centipawns. The UCI protocol also allows for evaluations to be expressed as upper or lower bounds. In positions where the engine finds a mate in some number of moves, the evaluation is given as "mate x" instead of a centipawn value.

The function convert_scores() will convert bounds or mates into numeric values. Values of "x upperbound" or "x lowerbound" will simply be converted to the numeric value of x. Values of "mate x" will be converted to the value specified by the mate parameter, in centipawns. The final scores will be returned as an integer vector.

Value

An numeric vector of scores (in centipawns).

Note

The UCI convention is that scores for white are given with the opposite sign from the scores for black (i.e., a positive score on black's turn means black is ahead, while a positive score on white's turn means white is ahead.) The function convert_scores() uses a different convention by default: the score for black will have the sign flipped to ensure that any time white is winning, score > 0, and any time black is winning score < 0. To override this behavior and use the UCI convention, set flip_signs to FALSE.

See Also

parse_gamelog() to extract scores from engine output.

Examples

scores <- c("90", "-26", "26 upperbound", "mate 1", "mate -1", "mate 0", NA)
convert_scores(scores)

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