mirror of
https://github.com/sigmasternchen/php-chess
synced 2025-03-15 07:58:54 +00:00
fix: Pawn can not capture forward
This commit is contained in:
parent
7259ddecb1
commit
73b090e9b7
2 changed files with 20 additions and 2 deletions
|
@ -25,10 +25,12 @@ class Pawn extends Piece {
|
|||
|
||||
$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);
|
||||
|
||||
if (!$this->hasMoved && !$occupied->has($initial)) {
|
||||
if (!$this->hasMoved && !$occupied->has($initial) && !$captureable->has($initial)) {
|
||||
$result->add($initial);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
$subject = new Pawn(
|
||||
new Position(3, 4),
|
||||
|
|
Loading…
Reference in a new issue