fix: Current side stays the same on apply in place

This commit is contained in:
sigmasternchen 2024-10-27 12:49:29 +01:00
parent 9f5b9c83e1
commit f36fba17d9
2 changed files with 22 additions and 0 deletions

View file

@ -319,6 +319,7 @@ class Game {
}
$this->current = $this->current->getNext();
$this->moveCache = null;
$this->history->add($this);
}

View file

@ -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());
}
}