Skip to content

Commit

Permalink
Updated ChessServer\Game\AbstractMode
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Jan 15, 2024
1 parent 33924bb commit adfa76f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Command/TutorFenCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ public function __construct()
$this->name = '/tutor_fen';
$this->description = "Explains a FEN position in terms of chess concepts.";
$this->params = [
// mandatory params
'variant' => '<string>',
'fen' => '<string>',
// optional params
'startPos' => '<string>',
];
}

public function validate(array $argv)
{
return count($argv) - 1 === count($this->params);
return count($argv) - 1 === count($this->params) || count($this->params) - 1;
}

public function run(ChesslaBlab $socket, array $argv, int $resourceId)
Expand Down
26 changes: 26 additions & 0 deletions src/Game/AbstractMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@
use Chess\Function\StandardFunction;
use Chess\Heuristics\FenHeuristics;
use Chess\Movetext\NagMovetext;
use Chess\Tutor\FenExplanation;
use Chess\UciEngine\Stockfish;
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 CapablancaFischerStrToBoard;
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\Game\Game;
use ChessServer\Command\HeuristicsCommand;
use ChessServer\Command\LegalCommand;
use ChessServer\Command\PlayLanCommand;
use ChessServer\Command\StockfishCommand;
use ChessServer\Command\StockfishEvalCommand;
use ChessServer\Command\TutorFenCommand;
use ChessServer\Command\UndoCommand;
use ChessServer\Exception\InternalErrorException;

Expand Down Expand Up @@ -105,6 +115,22 @@ public function res($argv, $cmd)
return [
$cmd->name => NagMovetext::glyph($nag),
];
case TutorFenCommand::class:
if ($argv[1] === Chess960Board::VARIANT) {
$startPos = str_split($argv[3]);
$board = (new Chess960FenStrToBoard($argv[2], $startPos))->create();
} elseif ($argv[1] === CapablancaBoard::VARIANT) {
$board = (new CapablancaFenStrToBoard($argv[2]))->create();
} elseif ($argv[1] === CapablancaFischerBoard::VARIANT) {
$startPos = str_split($argv[3]);
$board = (new CapablancaFischerStrToBoard($argv[2], $startPos))->create();
} elseif ($argv[1] === ClassicalBoard::VARIANT) {
$board = (new ClassicalFenStrToBoard($argv[2]))->create();
}
$paragraph = (new FenExplanation($board))->getParagraph();
return [
$cmd->name => implode(' ', $paragraph),
];
case UndoCommand::class:
$board = $this->game->getBoard()->undo();
$this->game->setBoard($board);
Expand Down

0 comments on commit adfa76f

Please sign in to comment.