Skip to content

Commit

Permalink
Implemented the /ascii command
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Nov 15, 2024
1 parent b036153 commit 6eb922e
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 6eb922e

Please sign in to comment.