diff --git a/docs/heuristics.md b/docs/heuristics.md index ac7d3202b..fa37d26bc 100644 --- a/docs/heuristics.md +++ b/docs/heuristics.md @@ -50,7 +50,7 @@ The evaluation features are used in several classes. ## Evaluation Function -[Chess\EvalArray](https://github.com/chesslablab/php-chess/blob/main/tests/unit/EvalArrayTest.php) allows to transform a FEN position to decimal numbers between -1 and +1. -1 is the best possible evaluation for Black and +1 the best possible evaluation for White. Both forces being set to 0 means they're balanced. +[Chess\EvalArray](https://github.com/chesslablab/php-chess/blob/main/tests/unit/EvalArrayTest.php) allows to transform a FEN position to numbers between -1 and +1. -1 is the best possible evaluation for Black and +1 the best possible evaluation for White. Both forces being set to 0 means they're balanced. ```php use Chess\EvalArray; @@ -149,7 +149,30 @@ Array ) ``` -The relative value of a position in FEN format without considering checkmate can be obtained by adding the above values. +As chess champion William Steinitz pointed out, a strong position can be created by accumulating small advantages. The relative value of the position without considering checkmate is obtained by counting the advantages in the evaluation array. + +```php +use Chess\EvalArray; +use Chess\FenToBoardFactory; +use Chess\Function\CompleteFunction; + +$fen = 'rnbqkb1r/p1pp1ppp/1p2pn2/8/2PP4/2N2N2/PP2PPPP/R1BQKB1R b KQkq -'; + +$board = FenToBoardFactory::create($fen); + +$normd = EvalArray::normalization(new CompleteFunction(), $board); +$count = EvalArray::count($normd); + +echo $count; +``` + +```text +1 +``` + +In this example, one evaluation feature is favoring White. + +An alternative way to look at it is to add up the values ​​in the evaluation array. ```php use Chess\EvalArray; @@ -169,7 +192,7 @@ echo $sum; 0.24 ``` -In this example, White is slightly better than Black because the value obtained is a positive number. +White is slightly better than Black because the value obtained is a positive number. This is an estimate that suggests who may be better without considering checkmate. Please note that a heuristic evaluation is not the same thing as a chess calculation. Heuristic evaluations are often correct but may fail because they are based on probabilities.