Skip to content

Commit

Permalink
Fix the mean
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Jan 2, 2025
1 parent 7bc158e commit d13983c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/EvalArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ public static function steinitz(AbstractFunction $f, AbstractBoard $board): int
*/
public static function mean(AbstractFunction $f, AbstractBoard $board): float
{
return round(array_sum(self::normalization($f, $board)), 2);
$normd = self::normalization($f, $board);
$sum = array_sum($normd);
$count = count($normd);

return round($sum / $count, 4);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/EvalArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function kaufman_06()
{
$expectedNormd = [ -1.0, -0.33, 0.01, 0.08, 0.08, 0.08, 0.08, 0.42, 1.0 ];
$expectedSteinitz = 5;
$expectedMean = 0.42;
$expectedMean = 0.0131;
$expectedMedian = 0.08;
$expectedMode = 0.08;

Expand Down Expand Up @@ -51,7 +51,7 @@ public function kaufman_07()
{
$expectedNormd = [ -1.0, -0.31, -0.31, 0.1, 0.1, 0.1, 0.58, 1.0 ];
$expectedSteinitz = 2;
$expectedMean = 0.26;
$expectedMean = 0.0081;
$expectedMedian = 0.1;
$expectedMode = 0.1;

Expand Down Expand Up @@ -79,7 +79,7 @@ public function kaufman_08()
{
$expectedNormd = [ -1.0, -0.4, -0.2, 0.09, 0.09, 0.09, 0.09, 0.11, 0.19, 0.3, 0.3, 0.35, 1.0 ];
$expectedSteinitz = 7;
$expectedMean = 1.01;
$expectedMean = 0.0316;
$expectedMedian = 0.09;
$expectedMode = 0.09;

Expand Down Expand Up @@ -107,7 +107,7 @@ public function no_mode()
{
$expectedNormd = [ -1.0, 0.24, 1.0 ];
$expectedSteinitz = 1;
$expectedMean = 0.24;
$expectedMean = 0.0075;
$expectedMedian = 0.24;
$expectedMode = null;

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 mean evaluation of this position is -0.92.",
"The mean evaluation of this position is -0.0287.",
];

$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 mean evaluation of this position is 0.89.",
"The mean evaluation of this position is 0.0278.",
];

$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 mean evaluation of this position is 0.32.",
"The mean evaluation of this position is 0.01.",
];

$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 mean evaluation of this position is 1.5.",
"The mean evaluation of this position is 0.0469.",
];

$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 mean evaluation of this position is 0.45.",
"The mean evaluation of this position is 0.0141.",
];

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

0 comments on commit d13983c

Please sign in to comment.