Skip to content

Commit

Permalink
Replaced direct object construction calls with a factory of objects
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Nov 25, 2024
1 parent 7d6e528 commit 9cee830
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/Command/Game/Async/HeuristicTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}

Expand Down

0 comments on commit 9cee830

Please sign in to comment.