-
Notifications
You must be signed in to change notification settings - Fork 24
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 #397 from chesslablab/issue/384-Parallelize-the-st…
…ockfish-command Issue/384 parallelize the stockfish command
- Loading branch information
Showing
8 changed files
with
72 additions
and
70 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
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
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
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
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,52 @@ | ||
<?php | ||
|
||
namespace ChessServer\Command\Game; | ||
|
||
use Chess\Computer\GrandmasterMove; | ||
use Chess\UciEngine\UciEngine; | ||
use Chess\UciEngine\Details\Limit; | ||
use Chess\Variant\Classical\Board; | ||
use ChessServer\Socket\AbstractSocket; | ||
use Spatie\Async\Task; | ||
|
||
class StockfishAsyncTask extends Task | ||
{ | ||
private array $params; | ||
|
||
private Board $board; | ||
|
||
private GrandmasterMove $gmMove; | ||
|
||
public function __construct($params, $board) | ||
{ | ||
$this->params = $params; | ||
$this->board = $board; | ||
} | ||
|
||
public function configure() | ||
{ | ||
$this->gmMove = new GrandmasterMove(AbstractSocket::DATA_FOLDER.'/players.json'); | ||
} | ||
|
||
public function run() | ||
{ | ||
if ($move = $this->gmMove->move($this->board)) { | ||
return $move; | ||
} | ||
|
||
$limit = new Limit(); | ||
$limit->depth = $this->params['params']['depth']; | ||
$stockfish = (new UciEngine('/usr/games/stockfish')) | ||
->setOption('Skill Level', $this->params['options']['Skill Level']); | ||
$analysis = $stockfish->analysis($this->board, $limit); | ||
|
||
$clone = $this->board->clone(); | ||
$clone->playLan($this->board->turn, $analysis['bestmove']); | ||
$history = $clone->history; | ||
$end = end($history); | ||
|
||
return [ | ||
'pgn' => $end['move']['pgn'], | ||
]; | ||
} | ||
} |
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
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
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