diff --git a/src/Command/RandomizerCommand.php b/src/Command/RandomizerCommand.php index e318b5a0..36145074 100644 --- a/src/Command/RandomizerCommand.php +++ b/src/Command/RandomizerCommand.php @@ -80,11 +80,11 @@ public function run(ChesslaBlabSocket $socket, array $argv, int $id) $color = array_key_first($items); $pieceIds = str_split(current($items)); if ($pieceIds === ['B', 'B']) { - $board = (new TwoBishopsRandomizer($argv[1]))->getBoard(); + $board = (new TwoBishopsRandomizer($argv[1]))->board; } elseif ($pieceIds === ['P']) { - $board = (new PawnEndgameRandomizer($argv[1]))->getBoard(); + $board = (new PawnEndgameRandomizer($argv[1]))->board; } else { - $board = (new Randomizer($argv[1], [$color => $pieceIds]))->getBoard(); + $board = (new Randomizer($argv[1], [$color => $pieceIds]))->board; } } else { $wIds = str_split($items[Color::W]); @@ -92,11 +92,11 @@ public function run(ChesslaBlabSocket $socket, array $argv, int $id) $board = (new Randomizer($argv[1], [ Color::W => $wIds, Color::B => $bIds, - ]))->getBoard(); + ]))->board; } return $socket->getClientStorage()->sendToOne($id, [ $this->name => [ - 'turn' => $board->getTurn(), + 'turn' => $board->turn, 'fen' => $board->toFen(), ], ]); diff --git a/src/Command/StartCommand.php b/src/Command/StartCommand.php index 3b387cc5..a5cb8aac 100644 --- a/src/Command/StartCommand.php +++ b/src/Command/StartCommand.php @@ -143,9 +143,8 @@ public function run(ChesslaBlabSocket $socket, array $argv, int $id) $sanPlay = new SanPlay($settings->movetext, $board); } $sanPlay->validate(); - $board = $sanPlay->getBoard(); $sanMode = new SanMode(new Game($argv[1], $argv[2]), [$id]); - $game = $sanMode->getGame()->setBoard($board); + $game = $sanMode->getGame()->setBoard($sanPlay->board); $sanMode->setGame($game); $socket->getGameModeStorage()->set($sanMode); return $socket->getClientStorage()->sendToOne($id, [ @@ -153,8 +152,8 @@ public function run(ChesslaBlabSocket $socket, array $argv, int $id) 'variant' => $argv[1], 'mode' => $argv[2], 'turn' => $game->state()->turn, - 'movetext' => $sanPlay->getSanMovetext()->validate(), - 'fen' => $sanPlay->getFen(), + 'movetext' => $sanPlay->sanMovetext->validate(), + 'fen' => $sanPlay->fen, ...($argv[1] === Game::VARIANT_960 ? ['startPos' => $settings->startPos] : [] diff --git a/src/Game/AbstractMode.php b/src/Game/AbstractMode.php index b78433d6..1568fa9a 100644 --- a/src/Game/AbstractMode.php +++ b/src/Game/AbstractMode.php @@ -74,8 +74,8 @@ public function res($argv, $cmd) $options = json_decode(stripslashes($argv[1]), true); $params = json_decode(stripslashes($argv[2]), true); $computer = $this->game->computer($options, $params); - if ($computer->pgn) { - $this->game->play($this->game->state()->turn, $computer->pgn); + if ($computer['pgn']) { + $this->game->play($this->game->state()->turn, $computer['pgn']); } } return [ diff --git a/src/Game/Game.php b/src/Game/Game.php index 6b73b5a5..146a5321 100644 --- a/src/Game/Game.php +++ b/src/Game/Game.php @@ -127,16 +127,16 @@ public function setBoard(ClassicalBoard $board): Game */ public function state(): object { - $history = $this->board->getHistory(); + $history = $this->board->history; $end = end($history); return (object) [ - 'turn' => $this->board->getTurn(), - 'pgn' => $end ? $end->move->pgn : null, - 'castlingAbility' => $this->board->getCastlingAbility(), - 'movetext' => $this->board->getMovetext(), + 'turn' => $this->board->turn, + 'pgn' => $end ? $end['move']['pgn'] : null, + 'castlingAbility' => $this->board->castlingAbility, + 'movetext' => $this->board->movetext(), 'fen' => $this->board->toFen(), - 'isCapture' => $end ? $end->move->isCapture : false, + 'isCapture' => $end ? $end['move']['isCapture'] : false, 'isCheck' => $this->board->isCheck(), 'isMate' => $this->board->isMate(), 'isStalemate' => $this->board->isStalemate(), @@ -152,9 +152,9 @@ public function state(): object * * @param array $options * @param array $params - * @return object|null + * @return array|null */ - public function computer(array $options = [], array $params = []): ?object + public function computer(array $options = [], array $params = []): ?array { if ($this->gmMove) { if ($move = $this->gmMove->move($this->board)) { @@ -162,17 +162,18 @@ public function computer(array $options = [], array $params = []): ?object } } - $limit = (new Limit())->setDepth($params['depth']); + $limit = new Limit(); + $limit->depth = $params['depth']; $stockfish = (new UciEngine('/usr/games/stockfish'))->setOption('Skill Level', $options['Skill Level']); $analysis = $stockfish->analysis($this->board, $limit); - $clone = unserialize(serialize($this->board)); - $clone->playLan($this->board->getTurn(), $analysis['bestmove']); - $history = $clone->getHistory(); + $clone = $this->board->clone(); + $clone->playLan($this->board->turn, $analysis['bestmove']); + $history = $clone->history; $end = end($history); - return (object) [ - 'pgn' => $end->move->pgn, + return [ + 'pgn' => $end['move']['pgn'], ]; } diff --git a/src/Game/PlayMode.php b/src/Game/PlayMode.php index 5e9b6d0f..d1d6bbb0 100644 --- a/src/Game/PlayMode.php +++ b/src/Game/PlayMode.php @@ -101,7 +101,7 @@ protected function updateTimer(string $color) { $now = time(); $diff = $now - $this->updatedAt; - if ($this->game->getBoard()->getTurn() === Color::B) { + if ($this->game->getBoard()->turn === Color::B) { $this->timer[Color::W] -= $diff; $this->timer[Color::W] += $this->getJwtDecoded()->increment; } else {