Skip to content

Commit

Permalink
Refactored enPassant()
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Jan 28, 2025
1 parent 705430d commit 6832e49
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Variant/AbstractBoard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down

0 comments on commit 6832e49

Please sign in to comment.