mirror of
https://github.com/sigmasternchen/php-chess
synced 2025-03-14 23:58:53 +00:00
fix: Current side stays the same on apply in place
This commit is contained in:
parent
9f5b9c83e1
commit
f36fba17d9
2 changed files with 22 additions and 0 deletions
|
@ -319,6 +319,7 @@ class Game {
|
|||
}
|
||||
|
||||
$this->current = $this->current->getNext();
|
||||
$this->moveCache = null;
|
||||
|
||||
$this->history->add($this);
|
||||
}
|
||||
|
|
|
@ -875,4 +875,25 @@ final class GameTest extends TestCase {
|
|||
array_map(fn($p) => $p->getPosition()->file, $kings),
|
||||
);
|
||||
}
|
||||
|
||||
public function testBug_moveCacheNotClearedOnApplyInPlace() {
|
||||
$subject = new Game(
|
||||
[
|
||||
new King(new Position(0, 7), Side::BLACK),
|
||||
new King(new Position(0, 0), Side::WHITE),
|
||||
],
|
||||
Side::WHITE
|
||||
);
|
||||
|
||||
$this->assertEquals(Side::WHITE, $subject->getCurrentSide());
|
||||
|
||||
$moves = $subject->getLegalMoves();
|
||||
$this->assertEquals(Side::WHITE, $moves[0]->getPiece()->getSide());
|
||||
$subject->applyInPlace($moves[0]);
|
||||
|
||||
$this->assertEquals(Side::BLACK, $subject->getCurrentSide());
|
||||
|
||||
$moves = $subject->getLegalMoves();
|
||||
$this->assertEquals(Side::BLACK, $moves[0]->getPiece()->getSide());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue