Skip to content

Commit

Permalink
Improved the relative fork elaboration
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Jan 30, 2025
1 parent 7d82f18 commit e8f828d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
10 changes: 7 additions & 3 deletions src/Eval/RelativeForkEval.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ public function __construct(AbstractBoard $board)
$attackedValue = self::$value[$val->id];
if ($pieceValue < $attackedValue) {
$this->result[$piece->color] += $attackedValue;
$this->toElaborate[] = $val;
$this->toElaborate[] = [
$piece,
$val,
];
}
}
}
Expand All @@ -67,8 +70,9 @@ public function __construct(AbstractBoard $board)
public function elaborate(): array
{
foreach ($this->toElaborate as $val) {
$this->elaboration[] = "Relative fork attack on " .
PiecePhrase::create($val) .
$this->elaboration[] = ucfirst(PiecePhrase::create($val[1])) .
" is under a fork attack by " .
PiecePhrase::create($val[0]) .
".";
}

Expand Down
12 changes: 6 additions & 6 deletions tests/unit/Eval/RelativeForkEvalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public function pawn_forks_bishop_and_knight()
];

$expectedElaboration = [
"Relative fork attack on the bishop on f6.",
"Relative fork attack on the knight on h6.",
"The bishop on f6 is under a fork attack by the pawn on g5.",
"The knight on h6 is under a fork attack by the pawn on g5.",
];

$board = (new StrToBoard('8/1k6/5b1n/6P1/7K/8/8/8 w - -'))
Expand Down Expand Up @@ -287,8 +287,8 @@ public function knight_forks_rook_and_rook()
];

$expectedElaboration = [
"Relative fork attack on the rook on b2.",
"Relative fork attack on the rook on d6.",
"The rook on b2 is under a fork attack by the knight on c4.",
"The rook on d6 is under a fork attack by the knight on c4.",
];

$board = (new StrToBoard('8/2k5/3r4/8/2N5/5K2/1r6/8 w - -'))
Expand Down Expand Up @@ -316,8 +316,8 @@ public function knight_forks_queen_and_rook()
];

$expectedElaboration = [
"Relative fork attack on White's queen on c4.",
"Relative fork attack on the rook on f7.",
"White's queen on c4 is under a fork attack by the knight on d6.",
"The rook on f7 is under a fork attack by the knight on d6.",
];

$board = (new StrToBoard('8/5R2/2kn4/8/2Q5/8/6K1/8 w - -'))
Expand Down

0 comments on commit e8f828d

Please sign in to comment.