-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #450 from chesslablab/issue/449-Implement-the-good…
…_pgn-command Issue/449 implement the good pgn command
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace ChessServer\Command\Game\Blocking; | ||
|
||
use ChessServer\Command\AbstractBlockingCommand; | ||
use ChessServer\Socket\AbstractSocket; | ||
|
||
class TutorGoodPgnCommand extends AbstractBlockingCommand | ||
{ | ||
public function __construct() | ||
{ | ||
$this->name = '/tutor_good_pgn'; | ||
$this->description = "Explains the why of a good move in terms of chess concepts."; | ||
} | ||
|
||
public function validate(array $argv) | ||
{ | ||
return count($argv) - 1 === 0; | ||
} | ||
|
||
public function run(AbstractSocket $socket, array $argv, int $id) | ||
{ | ||
$game = $socket->getGameModeStorage()->getById($id)->getGame(); | ||
|
||
if (!isset($game->state()->end)) { | ||
$this->pool->add(new TutorGoodPgnTask($game->getBoard())) | ||
->then(function ($result) use ($socket, $id, $game) { | ||
return $socket->getClientStorage()->send([$id], [ | ||
$this->name => $result, | ||
]); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace ChessServer\Command\Game\Blocking; | ||
|
||
use Chess\Eval\CompleteFunction; | ||
use Chess\Tutor\GoodPgnEvaluation; | ||
use Chess\UciEngine\UciEngine; | ||
use Chess\UciEngine\Details\Limit; | ||
use Chess\Variant\Classical\Board; | ||
use ChessServer\Command\AbstractBlockingTask; | ||
use ChessServer\Socket\AbstractSocket; | ||
|
||
class TutorGoodPgnTask extends AbstractBlockingTask | ||
{ | ||
private Board $board; | ||
|
||
public function __construct(Board $board) | ||
{ | ||
parent::__construct(); | ||
|
||
$this->board = $board; | ||
} | ||
|
||
public function run() | ||
{ | ||
$limit = new Limit(); | ||
$limit->depth = 12; | ||
$stockfish = new UciEngine('/usr/games/stockfish'); | ||
$f = new CompleteFunction(); | ||
|
||
$goodPgnEvaluation = new GoodPgnEvaluation($limit, $stockfish, $f, $this->board); | ||
|
||
return [ | ||
'pgn' => $goodPgnEvaluation->pgn, | ||
'paragraph' => implode(' ', $goodPgnEvaluation->paragraph), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters