Skip to content

Commit

Permalink
Added Capablanca variants
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Nov 25, 2024
1 parent b0823b6 commit 1e33cf3
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 15 deletions.
28 changes: 14 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions src/Command/Game/Async/HeuristicTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

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;
Expand All @@ -19,6 +23,15 @@ public function run()
$board = isset($this->params['fen'])
? (new Chess960FenStrToBoard($this->params['fen'], $startPos))->create()
: new Chess960Board($startPos);
} elseif ($this->params['variant'] === CapablancaBoard::VARIANT) {
$board = isset($this->params['fen'])
? (new CapablancaFenStrToBoard($this->params['fen']))->create()
: 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()
: new CapablancaFischerBoard($startPos);
} elseif ($this->params['variant'] === ClassicalBoard::VARIANT) {
$board = isset($this->params['fen'])
? (new ClassicalFenStrToBoard($this->params['fen']))->create()
Expand Down
5 changes: 5 additions & 0 deletions src/Command/Game/Async/RestartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ChessServer\Command\Game\Async;

use Chess\Variant\CapablancaFischer\FEN\StrToBoard as CapablancaFischerFenStrToBoard;
use Chess\Variant\Chess960\FEN\StrToBoard as Chess960FenStrToBoard;
use Chess\Variant\Classical\PGN\AN\Color;
use ChessServer\Command\AbstractAsyncCommand;
Expand Down Expand Up @@ -36,6 +37,10 @@ public function run(AbstractSocket $socket, array $argv, int $id)
$startPos = str_split($result->startPos);
$board = (new Chess960FenStrToBoard($result->fen, $startPos))->create();
$game = (new Game($result->variant, Game::MODE_PLAY))->setBoard($board);
} elseif ($result->variant === Game::VARIANT_CAPABLANCA_FISCHER) {
$startPos = str_split($result->startPos);
$board = (new CapablancaFischerFenStrToBoard($result->fen, $startPos))->create();
$game = (new Game($result->variant, Game::MODE_PLAY))->setBoard($board);
} else {
$game = new Game($result->variant, Game::MODE_PLAY);
}
Expand Down
10 changes: 10 additions & 0 deletions src/Command/Game/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace ChessServer\Command\Game;

use Chess\Variant\AbstractBoard;
use Chess\Variant\Capablanca\Board as CapablancaBoard;
use Chess\Variant\CapablancaFischer\Board as CapablancaFischerBoard;
use Chess\Variant\CapablancaFischer\StartPosition as CapablancaFischerStartPosition;
use Chess\Variant\Chess960\Board as Chess960Board;
use Chess\Variant\Chess960\StartPosition as Chess960StartPosition;
use Chess\Variant\Classical\Board as ClassicalBoard;
Expand All @@ -15,6 +18,8 @@
class Game
{
const VARIANT_960 = Chess960Board::VARIANT;
const VARIANT_CAPABLANCA = CapablancaBoard::VARIANT;
const VARIANT_CAPABLANCA_FISCHER = CapablancaFischerBoard::VARIANT;
const VARIANT_CLASSICAL = ClassicalBoard::VARIANT;
const VARIANT_DUNSANY = DunsanyBoard::VARIANT;
const VARIANT_LOSING = LosingBoard::VARIANT;
Expand Down Expand Up @@ -42,6 +47,11 @@ public function __construct(string $variant, string $mode)
if ($this->variant === self::VARIANT_960) {
$startPos = (new Chess960StartPosition())->create();
$this->board = new Chess960Board($startPos);
} elseif ($this->variant === self::VARIANT_CAPABLANCA) {
$this->board = new CapablancaBoard();
} elseif ($this->variant === self::VARIANT_CAPABLANCA_FISCHER) {
$startPos = (new CapablancaFischerStartPosition())->create();
$this->board = new CapablancaFischerBoard($startPos);
} elseif ($this->variant === self::VARIANT_CLASSICAL) {
$this->board = new ClassicalBoard();
} elseif ($this->variant === self::VARIANT_DUNSANY) {
Expand Down
40 changes: 39 additions & 1 deletion src/Command/Game/Sync/StartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

use Chess\FenToBoardFactory;
use Chess\Play\SanPlay;
use Chess\Variant\Capablanca\Board as CapablancaBoard;
use Chess\Variant\CapablancaFischer\Board as CapablancaFischerBoard;
use Chess\Variant\CapablancaFischer\StartPosition as CapablancaFischerStartPosition;
use Chess\Variant\Chess960\Board as Chess960Board;
use Chess\Variant\Chess960\StartPosition as Chess960StartPosition;
use Chess\Variant\Chess960\FEN\StrToBoard as Chess960FenStrToBoard;
use Chess\Variant\Classical\Board as ClassicalBoard;
use Chess\Variant\Classical\PGN\AN\Color;
use Chess\Variant\Dunsany\Board as DunsanyBoard;
Expand Down Expand Up @@ -50,6 +52,18 @@ public function run(AbstractSocket $socket, array $argv, int $id)
$startPos = (new Chess960StartPosition())->create();
$board = new Chess960Board($startPos);
}
} elseif ($params['variant'] === Game::VARIANT_CAPABLANCA) {
$board = isset($params['settings']['fen'])
? FenToBoardFactory::create($params['settings']['fen'], new CapablancaBoard())
: new CapablancaBoard();
} elseif ($params['variant'] === Game::VARIANT_CAPABLANCA_FISCHER) {
if (isset($params['settings']['startPos']) && isset($params['settings']['fen'])) {
$startPos = str_split($params['settings']['startPos']);
$board = FenToBoardFactory::create($params['settings']['fen'], new CapablancaFischerBoard($startPos));
} else {
$startPos = (new CapablancaFischerStartPosition())->create();
$board = new CapablancaFischerBoard($startPos);
}
} elseif ($params['variant'] === Game::VARIANT_DUNSANY) {
$board = isset($params['settings']['fen'])
? FenToBoardFactory::create($params['settings']['fen'], new DunsanyBoard())
Expand Down Expand Up @@ -84,6 +98,10 @@ public function run(AbstractSocket $socket, array $argv, int $id)
? ['startPos' => implode('', $startPos)]
: []
),
...($params['variant'] === Game::VARIANT_CAPABLANCA_FISCHER
? ['startPos' => implode('', $startPos)]
: []
),
],
]);
} catch (\Throwable $e) {
Expand All @@ -103,6 +121,18 @@ public function run(AbstractSocket $socket, array $argv, int $id)
$startPos = (new Chess960StartPosition())->create();
$board = new Chess960Board($startPos);
}
} elseif ($params['variant'] === Game::VARIANT_CAPABLANCA) {
$board = isset($params['settings']['fen'])
? FenToBoardFactory::create($params['settings']['fen'], new CapablancaBoard())
: new CapablancaBoard();
} elseif ($params['variant'] === Game::VARIANT_CAPABLANCA_FISCHER) {
if (isset($params['settings']['startPos']) && isset($params['settings']['fen'])) {
$startPos = str_split($params['settings']['startPos']);
$board = FenToBoardFactory::create($params['settings']['fen'], new CapablancaFischerBoard($startPos));
} else {
$startPos = (new CapablancaFischerStartPosition())->create();
$board = new CapablancaFischerBoard($startPos);
}
} elseif ($params['variant'] === Game::VARIANT_DUNSANY) {
$board = isset($params['settings']['fen'])
? FenToBoardFactory::create($params['settings']['fen'], new DunsanyBoard())
Expand Down Expand Up @@ -151,6 +181,10 @@ public function run(AbstractSocket $socket, array $argv, int $id)
? ['startPos' => implode('', $game->getBoard()->getStartPos())]
: []
),
...($params['variant'] === Game::VARIANT_CAPABLANCA_FISCHER
? ['startPos' => implode('', $game->getBoard()->getStartPos())]
: []
),
...(isset($params['settings']['fen'])
? ['fen' => $params['settings']['fen']]
: []
Expand Down Expand Up @@ -182,6 +216,10 @@ public function run(AbstractSocket $socket, array $argv, int $id)
? ['startPos' => implode('', $game->getBoard()->getStartPos())]
: []
),
...($params['variant'] === Game::VARIANT_CAPABLANCA_FISCHER
? ['startPos' => implode('', $game->getBoard()->getStartPos())]
: []
),
],
]);
} catch (\Throwable $e) {
Expand Down

0 comments on commit 1e33cf3

Please sign in to comment.