fix: Pawn can not capture forward

This commit is contained in:
overflowerror 2024-01-06 21:24:46 +01:00
parent 7259ddecb1
commit 73b090e9b7
2 changed files with 20 additions and 2 deletions

View file

@ -25,10 +25,12 @@ class Pawn extends Piece {
$initial = new Position($file, $rank + 2 * $direction); $initial = new Position($file, $rank + 2 * $direction);
if (!$occupied->has($regular)) { // checking for collisions in the captureable map works because there is always
// a pawn before the en passant square.
if (!$occupied->has($regular) && !$captureable->has($regular)) {
$result->add($regular); $result->add($regular);
if (!$this->hasMoved && !$occupied->has($initial)) { if (!$this->hasMoved && !$occupied->has($initial) && !$captureable->has($initial)) {
$result->add($initial); $result->add($initial);
} }
} }

View file

@ -155,6 +155,22 @@ final class PawnTest extends TestCase {
); );
} }
public function testMoves_bug_captureForwardNotAllowed() {
$subject = new Pawn(
new Position(4, 3),
Side::BLACK,
true
);
$result = $subject->getMoveCandidateMap(
FieldBitMap::empty(),
new FieldBitMap([new Position(4, 2)]),
FieldBitMap::empty());
$this->assertTrue(
$result->isEmpty()
);
}
public function testCaptureable_default() { public function testCaptureable_default() {
$subject = new Pawn( $subject = new Pawn(
new Position(3, 4), new Position(3, 4),