Skip to content

Commit

Permalink
Updated Chess\Tutor\FenEvaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Dec 31, 2024
1 parent b12ed9a commit bd6fe4e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
18 changes: 7 additions & 11 deletions src/Tutor/FenEvaluation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Chess\Eval\ExplainEvalTrait;
use Chess\Eval\ElaborateEvalTrait;
use Chess\Function\AbstractFunction;
use Chess\Labeller\SumLabeller;
use Chess\Variant\AbstractBoard;

class FenEvaluation extends AbstractParagraph
Expand All @@ -15,14 +14,11 @@ public function __construct(AbstractFunction $f, AbstractBoard $board)
{
$this->f = $f;
$this->board = $board;

$normd = EvalArray::normalization($this->f, $this->board);

$this->paragraph = [
...$this->fenExplanation(),
...$this->fenElaboration(),
...$this->steinitz($this->f, $this->board),
...$this->sum($normd),
...$this->steinitz(),
...$this->mean(),
];
}

Expand Down Expand Up @@ -58,9 +54,9 @@ private function fenElaboration(): array
return $paragraph;
}

private function steinitz(AbstractFunction $f, AbstractBoard $board): array
private function steinitz(): array
{
$steinitz = EvalArray::steinitz($f, $board);
$steinitz = EvalArray::steinitz($this->f, $this->board);

if ($steinitz > 0) {
$color = 'White';
Expand All @@ -76,12 +72,12 @@ private function steinitz(AbstractFunction $f, AbstractBoard $board): array
];
}

private function sum(array $normd): array
private function mean(): array
{
$sum = round(array_sum($normd), 2);
$mean = EvalArray::mean($this->f, $this->board);

return [
"The relative evaluation of this position is {$sum}.",
"The mean evaluation of this position is {$mean}.",
];
}

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Tutor/FenEvaluationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function A08()
"Black's king has more safe squares to move to than its counterpart.",
"These pieces are hanging: The rook on a8, the rook on h8, the pawn on c5, the rook on a1, the rook on h1.",
"Overall, 2 evaluation features are favoring Black.",
"The relative evaluation of this position is -0.92.",
"The mean evaluation of this position is -0.92.",
];

$A08 = file_get_contents(self::DATA_FOLDER.'/sample/A08.pgn');
Expand All @@ -54,7 +54,7 @@ public function capablanca_f4()
"White's king has more safe squares to move to than its counterpart.",
"These pieces are hanging: The pawn on f4, the pawn on i2, the rook on a1, White's archbishop on c1, White's chancellor on h1, the rook on j1, the rook on a8, Black's archbishop on c8, Black's chancellor on h8, the rook on j8, the pawn on i7.",
"Overall, 3 evaluation features are favoring White.",
"The relative evaluation of this position is 0.89.",
"The mean evaluation of this position is 0.89.",
];

$board = FenToBoardFactory::create(
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Tutor/GoodPgnEvaluationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function D07()
"These pieces are hanging: Black's queen on d5, the rook on a8, the rook on h8, the pawn on b7, the pawn on c7, the pawn on g7, the bishop on g4, the rook on h1.",
"The knight on e2 is pinned shielding a piece that is more valuable than the attacking piece.",
"Overall, 7 evaluation features are favoring Black.",
"The relative evaluation of this position is 0.32.",
"The mean evaluation of this position is 0.32.",
];

$limit = new Limit();
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Tutor/PgnEvaluationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function A08()
"The pawn on c5 is unprotected.",
"The pawn on c5 is under threat of being attacked.",
"Overall, 0 evaluation features are favoring either player.",
"The relative evaluation of this position is 1.5.",
"The mean evaluation of this position is 1.5.",
];

$A08 = file_get_contents(self::DATA_FOLDER.'/sample/A08.pgn');
Expand All @@ -56,7 +56,7 @@ public function endgame()
"These pieces are hanging: The bishop on e6.",
"The bishop on e6 is unprotected.",
"Overall, 4 evaluation features are favoring White.",
"The relative evaluation of this position is 0.45.",
"The mean evaluation of this position is 0.45.",
];

$board = FenToBoardFactory::create('8/5k2/4n3/8/8/1BK5/1B6/8 w - - 0 1');
Expand Down

0 comments on commit bd6fe4e

Please sign in to comment.