get_coercion: Gets the coercion of a chess position

View source: R/get_coercion.R

get_coercionR Documentation

Gets the coercion of a chess position

Description

The get_coercion() function calculates the difference in evaluation between the best and second best moves in a chess position, referred to here as the coercion of the position.

Usage

get_coercion(positionlog, depth = NULL)

Arguments

positionlog

A character vector of engine analysis

depth

A single-element integer vector of the desired search depth (# of plies)

Details

In chess, forcing moves are moves that give the opponent only a small number of ways to avoid an unfavorable position. Guid and Bratko (see references) used the difference in engine evaluation between the best and second best moves in a position as a measure of how forcing a position is.

Given a log of engine analysis of a chess position produced by one of rbitr's evaluation functions, get_coercion() will compute the difference in evaluation between the best and second best moves.

get_coercion() requires as input a positionlog of engine analysis. The analysis must contain at least two principal variations (pv's) to allow the coercion to be determined. If only one PV is provided, or if no move is possible (i.e., in positions of mate or stalemate) it will return Inf. The highest depth of search available will be used by default.

Value

A single-element numeric vector of the coercion for the position.

Note

When only one PV is available, this may be because there is only one legal move, or because the engine only analyzed one PV. When more than one legal move exists, but the engine only analyzed one PV, it might make more sense to consider the coercion to be NA. However, at present, get_coercion() can't distinguish between these two cases and returns Inf for either.

References

Guid, M.; Bratko, I. Computer Analysis of World Chess Champions. ICGA Journal 2006, 29 (2), 65–73.

See Also

The 'evaluate' functions produce analysis logs.

  • evaluate_position() for analyzing chess positions.

  • evaluate_game() for analyzing individual games.

  • evaluate_pgn() for evaluating all the games in a PGN file.

Examples

positionlog <- c(
  "Stockfish 13 by the Stockfish developers (see AUTHORS file)",
  "readyok",
  "info string NNUE evaluation using nn-62ef826d1a6d.nnue enabled",
  "info depth 1 seldepth 1 multipv 1 score cp 161 nodes 59 nps 59000 tbhits 0 time 1 pv b1c3",
  "info depth 1 seldepth 1 multipv 2 score cp 146 nodes 59 nps 59000 tbhits 0 time 1 pv d2d4",
  "info depth 2 seldepth 2 multipv 1 score cp 195 nodes 147 nps 73500 tbhits 0 time 2 pv d2d4 g8f6",
  "info depth 2 seldepth 2 multipv 2 score cp 170 nodes 147 nps 73500 tbhits
  0 time 2 pv h2h4 g8f6 h4g5",
  "bestmove d2d4 ponder g8f6"
)

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