From 6832e49a841ff6ac4936454194d3a55a9b1cd8cb Mon Sep 17 00:00:00 2001 From: standard Date: Tue, 28 Jan 2025 16:56:13 +0100 Subject: [PATCH] Refactored enPassant() --- src/Variant/AbstractBoard.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Variant/AbstractBoard.php b/src/Variant/AbstractBoard.php index e5b7054a..baf26d1b 100644 --- a/src/Variant/AbstractBoard.php +++ b/src/Variant/AbstractBoard.php @@ -647,12 +647,12 @@ public function enPassant(): string if ($last['id'] === Piece::P) { $prevFile = substr($last['from'], 1); $nextFile = substr($last['to'], 1); - if ($last['color'] === Color::W) { - if ($nextFile - $prevFile === 2) { + if (abs($nextFile - $prevFile) === 2) { + if ($last['color'] === Color::W) { return $last['from'][0] . $prevFile + 1; + } else { + return $last['from'][0] . $prevFile - 1; } - } elseif ($prevFile - $nextFile === 2) { - return $last['from'][0] . $prevFile - 1; } } }