From 2f3d5a33403942a435d1c82beba2f4b3c3eb0fa7 Mon Sep 17 00:00:00 2001 From: overflowerror Date: Fri, 5 Jan 2024 15:15:58 +0100 Subject: [PATCH] fix: Apply move doesn't create correct kings reference --- src/Game/Game.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Game/Game.php b/src/Game/Game.php index 99449f6..724002e 100644 --- a/src/Game/Game.php +++ b/src/Game/Game.php @@ -203,7 +203,10 @@ class Game { } public function apply(Move $move): Game { - $game = clone $this; + $game = new Game( + array_map(fn($p) => clone $p, $this->pieces), + $this->current, + ); if ($move->captures) { $game->removePiece($move->captures); @@ -240,10 +243,6 @@ class Game { return GameState::DEFAULT; } - public function __clone(): void { - $this->pieces = array_map(fn($p) => clone $p, $this->pieces); - } - public function visualize(): string { $result = " ";