Skip to content

Commit

Permalink
Updated Chess\Eval\AbsolutePinEval
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Jan 27, 2025
1 parent 2120e1e commit f9098df
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
12 changes: 8 additions & 4 deletions src/Eval/AbsolutePinEval.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ public function __construct(AbstractBoard $board)
];

foreach ($this->board->pieces() as $piece) {
if ($piece->isPinned()) {
if ($pinning = $piece->isPinned()) {
$this->result[$piece->color] += self::$value[$piece->id];
$this->toElaborate[] = $piece;
$this->toElaborate[] = [
$piece,
$pinning,
];
}
}
}
Expand All @@ -57,8 +60,9 @@ public function __construct(AbstractBoard $board)
public function elaborate(): array
{
foreach ($this->toElaborate as $val) {
$phrase = PiecePhrase::create($val);
$this->elaboration[] = ucfirst("$phrase is pinned shielding the king so it cannot move out of the line of attack because the king would be put in check.");
$pinned = PiecePhrase::create($val[0]);
$pinning = PiecePhrase::create($val[1]);
$this->elaboration[] = ucfirst("$pinned is pinned shielding the king so it cannot move out of the line of attack of $pinning because the king would be put in check.");
}

return $this->elaboration;
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/Eval/AbsolutePinEvalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function c62_ruy_lopez_steinitz_defense()
];

$expectedElaboration = [
"The knight on c6 is pinned shielding the king so it cannot move out of the line of attack because the king would be put in check.",
"The knight on c6 is pinned shielding the king so it cannot move out of the line of attack of the bishop on b5 because the king would be put in check.",
];

$absPinEval = new AbsolutePinEval($board);
Expand All @@ -45,7 +45,7 @@ public function c62_ruy_lopez_steinitz_defense_center_gambit_Bg4()
];

$expectedElaboration = [
"The knight on c6 is pinned shielding the king so it cannot move out of the line of attack because the king would be put in check.",
"The knight on c6 is pinned shielding the king so it cannot move out of the line of attack of the bishop on b5 because the king would be put in check.",
];

$absPinEval = new AbsolutePinEval($board);
Expand All @@ -68,8 +68,8 @@ public function both_knights_pinned()
];

$expectedElaboration = [
"The knight on c6 is pinned shielding the king so it cannot move out of the line of attack because the king would be put in check.",
"The knight on c3 is pinned shielding the king so it cannot move out of the line of attack because the king would be put in check.",
"The knight on c6 is pinned shielding the king so it cannot move out of the line of attack of the bishop on b5 because the king would be put in check.",
"The knight on c3 is pinned shielding the king so it cannot move out of the line of attack of the bishop on b4 because the king would be put in check.",
];

$absPinEval = new AbsolutePinEval($board);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Eval/CompleteFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function absolute_pin()
];

$expectedElaboration = [
"The knight on c6 is pinned shielding the king so it cannot move out of the line of attack because the king would be put in check.",
"The knight on c6 is pinned shielding the king so it cannot move out of the line of attack of the bishop on b5 because the king would be put in check.",
];

$board = FenToBoardFactory::create('r1bqkbnr/ppp2ppp/2np4/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R w KQkq -');
Expand Down

0 comments on commit f9098df

Please sign in to comment.