Skip to content

Commit

Permalink
Improved the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Dec 24, 2024
1 parent fca867b commit 6e8f7fa
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions docs/heuristics.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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.

Expand Down

0 comments on commit 6e8f7fa

Please sign in to comment.