Skip to content

Commit

Permalink
Merge pull request #429 from chesslablab/issue/427-implement-the-asci…
Browse files Browse the repository at this point in the history
…i-command

Implemented the /ascii command
  • Loading branch information
programarivm authored Nov 15, 2024
2 parents b036153 + 6eb922e commit b94c66e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Command/Game/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use ChessServer\Command\Game\Async\StockfishCommand;
use ChessServer\Command\Game\Async\TutorFenCommand;
use ChessServer\Command\Game\Sync\AcceptPlayRequestCommand;
use ChessServer\Command\Game\Sync\AsciiCommand;
use ChessServer\Command\Game\Sync\DrawCommand;
use ChessServer\Command\Game\Sync\EvalNamesCommand;
use ChessServer\Command\Game\Sync\LegalCommand;
Expand All @@ -32,6 +33,7 @@ public function __construct(Pool $pool)
parent::__construct();

// text-based commands
$this->commands->attach(new AsciiCommand());
$this->commands->attach(new EvalNamesCommand());
$this->commands->attach(new OnlineGamesCommand());
$this->commands->attach(new UndoCommand());
Expand Down
29 changes: 29 additions & 0 deletions src/Command/Game/Sync/AsciiCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace ChessServer\Command\Game\Sync;

use ChessServer\Command\AbstractSyncCommand;
use ChessServer\Socket\AbstractSocket;

class AsciiCommand extends AbstractSyncCommand
{
public function __construct()
{
$this->name = '/ascii';
$this->description = 'Returns an ASCII representation of the board.';
}

public function validate(array $argv)
{
return count($argv) - 1 === 0;
}

public function run(AbstractSocket $socket, array $argv, int $id)
{
$gameMode = $socket->getGameModeStorage()->getById($id);

return $socket->getClientStorage()->send([$id], [
$this->name => $gameMode->getGame()->getBoard()->toString(),
]);
}
}

0 comments on commit b94c66e

Please sign in to comment.