From 9cee830f671dbc5947c7daee53164cc05d8041d0 Mon Sep 17 00:00:00 2001 From: programarivm Date: Mon, 25 Nov 2024 10:37:48 +0100 Subject: [PATCH] Replaced direct object construction calls with a factory of objects --- src/Command/Game/Async/HeuristicTask.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Command/Game/Async/HeuristicTask.php b/src/Command/Game/Async/HeuristicTask.php index 2b11c38..d1c4a3f 100644 --- a/src/Command/Game/Async/HeuristicTask.php +++ b/src/Command/Game/Async/HeuristicTask.php @@ -2,16 +2,13 @@ namespace ChessServer\Command\Game\Async; +use Chess\FenToBoardFactory; use Chess\SanHeuristics; use Chess\Function\CompleteFunction; use Chess\Variant\Capablanca\Board as CapablancaBoard; -use Chess\Variant\Capablanca\FEN\StrToBoard as CapablancaFenStrToBoard; use Chess\Variant\CapablancaFischer\Board as CapablancaFischerBoard; -use Chess\Variant\CapablancaFischer\FEN\StrToBoard as CapablancaFischerFenStrToBoard; use Chess\Variant\Chess960\Board as Chess960Board; -use Chess\Variant\Chess960\FEN\StrToBoard as Chess960FenStrToBoard; use Chess\Variant\Classical\Board as ClassicalBoard; -use Chess\Variant\Classical\FEN\StrToBoard as ClassicalFenStrToBoard; use ChessServer\Command\AbstractAsyncTask; class HeuristicTask extends AbstractAsyncTask @@ -21,20 +18,20 @@ public function run() if ($this->params['variant'] === Chess960Board::VARIANT) { $startPos = str_split($this->params['startPos']); $board = isset($this->params['fen']) - ? (new Chess960FenStrToBoard($this->params['fen'], $startPos))->create() + ? FenToBoardFactory::create($this->params['fen'], new Chess960Board($startPos)) : new Chess960Board($startPos); } elseif ($this->params['variant'] === CapablancaBoard::VARIANT) { $board = isset($this->params['fen']) - ? (new CapablancaFenStrToBoard($this->params['fen']))->create() + ? FenToBoardFactory::create($this->params['fen'], new CapablancaBoard()) : new CapablancaBoard(); } elseif ($this->params['variant'] === CapablancaFischerBoard::VARIANT) { $startPos = str_split($this->params['startPos']); $board = isset($this->params['fen']) - ? (new CapablancaFischerFenStrToBoard($this->params['fen'], $startPos))->create() + ? FenToBoardFactory::create($this->params['fen'], new CapablancaFischerBoard($startPos)) : new CapablancaFischerBoard($startPos); } elseif ($this->params['variant'] === ClassicalBoard::VARIANT) { $board = isset($this->params['fen']) - ? (new ClassicalFenStrToBoard($this->params['fen']))->create() + ? FenToBoardFactory::create($this->params['fen'], new ClassicalBoard()) : new ClassicalBoard(); }