Skip to content

Commit

Permalink
Merge pull request #298 from chesslablab/issue/297-Racing-Kings-chess…
Browse files Browse the repository at this point in the history
…-implementation

Allowed to play Racing Kings chess
  • Loading branch information
programarivm authored Jul 9, 2024
2 parents 9474bb5 + a15de14 commit 6c8f984
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Command/StartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Chess\Variant\Classical\PGN\AN\Color;
use Chess\Variant\Dunsany\Board as DunsanyBoard;
use Chess\Variant\Dunsany\FEN\StrToBoard as DunsanyFenStrToBoard;
use Chess\Variant\RacingKings\Board as RacingKingsBoard;
use Chess\Variant\RacingKings\FEN\StrToBoard as RacingKingsFenStrToBoard;
use ChessServer\Game\Game;
use ChessServer\Game\FenMode;
use ChessServer\Game\PlayMode;
Expand All @@ -32,6 +34,7 @@ public function __construct()
Game::VARIANT_960,
Game::VARIANT_CLASSICAL,
Game::VARIANT_DUNSANY,
Game::VARIANT_RACING_KINGS,
],
// mandatory param
'mode' => [
Expand Down Expand Up @@ -100,6 +103,12 @@ public function run(ChesslaBlabSocket $socket, array $argv, int $id)
} else {
$board = new DunsanyBoard();
}
} elseif ($argv[1] === Game::VARIANT_RACING_KINGS) {
if (isset($settings->fen)) {
$board = (new RacingKingsFenStrToBoard($settings->fen))->create();
} else {
$board = new RacingKingsBoard();
}
} else {
if (isset($settings->fen)) {
$board = (new ClassicalFenStrToBoard($settings->fen))->create();
Expand Down Expand Up @@ -150,6 +159,12 @@ public function run(ChesslaBlabSocket $socket, array $argv, int $id)
$board = FenToBoardFactory::create($settings->fen, $board);
}
$sanPlay = new SanPlay($settings->movetext, $board);
} elseif ($argv[1] === Game::VARIANT_RACING_KINGS) {
$board = new RacingKingsBoard();
if (isset($settings->fen)) {
$board = FenToBoardFactory::create($settings->fen, $board);
}
$sanPlay = new SanPlay($settings->movetext, $board);
} else {
$board = new ClassicalBoard();
if (isset($settings->fen)) {
Expand Down Expand Up @@ -195,6 +210,9 @@ public function run(ChesslaBlabSocket $socket, array $argv, int $id)
} elseif ($argv[1] === Game::VARIANT_DUNSANY) {
$board = (new DunsanyFenStrToBoard($settings->fen))
->create();
} elseif ($argv[1] === Game::VARIANT_RACING_KINGS) {
$board = (new RacingKingsFenStrToBoard($settings->fen))
->create();
} else {
$board = (new ClassicalFenStrToBoard($settings->fen))
->create();
Expand All @@ -214,6 +232,8 @@ public function run(ChesslaBlabSocket $socket, array $argv, int $id)
$board = new Chess960Board($startPos);
} elseif ($argv[1] === Game::VARIANT_DUNSANY) {
$board = new DunsanyBoard();
} elseif ($argv[1] === Game::VARIANT_RACING_KINGS) {
$board = new RacingKingsBoard();
} else {
$board = new ClassicalBoard();
}
Expand Down
4 changes: 4 additions & 0 deletions src/Game/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Chess\Variant\Chess960\StartPosition as Chess960StartPosition;
use Chess\Variant\Classical\Board as ClassicalBoard;
use Chess\Variant\Dunsany\Board as DunsanyBoard;
use Chess\Variant\RacingKings\Board as RacingKingsBoard;

/**
* Game
Expand All @@ -22,6 +23,7 @@ class Game
const VARIANT_960 = Chess960Board::VARIANT;
const VARIANT_CLASSICAL = ClassicalBoard::VARIANT;
const VARIANT_DUNSANY = DunsanyBoard::VARIANT;
const VARIANT_RACING_KINGS = RacingKingsBoard::VARIANT;

const MODE_FEN = 'fen';
const MODE_PLAY = 'play';
Expand Down Expand Up @@ -79,6 +81,8 @@ public function __construct(
$this->board = new ClassicalBoard();
} elseif ($this->variant === self::VARIANT_DUNSANY) {
$this->board = new DunsanyBoard();
} elseif ($this->variant === self::VARIANT_RACING_KINGS) {
$this->board = new RacingKingsBoard();
}
}

Expand Down

0 comments on commit 6c8f984

Please sign in to comment.