Example #1
0
     if ($read === true) {
         readFromEngine($block);
     }
 }
 readFromEngine();
 writeToEngine('uci');
 writeToEngine('setoption name Hash value ' . UCI_HASH_SIZE_MB, false);
 writeToEngine('isready');
 writeToEngine('ucinewgame', false);
 SmrSession::$game_id = NPC_GAME_ID;
 require_once get_file_loc('ChessGame.class.inc');
 while (true) {
     //Redefine MICRO_TIME and TIME, the rest of the game expects them to be the single point in time that the script is executing, with it being redefined for each page load - unfortunately NPCs are one consistent script so we have to do a hack and redefine it (or change every instance of the TIME constant).
     runkit_constant_redefine('MICRO_TIME', microtime());
     runkit_constant_redefine('TIME', (int) microtimeSec(MICRO_TIME));
     $chessGames =& ChessGame::getNPCMoveGames(true);
     foreach ($chessGames as &$chessGame) {
         debug('Looking at game: ' . $chessGame->getChessGameID());
         writeToEngine('position fen ' . $chessGame->getFENString(), false);
         writeToEngine('go ' . ($chessGame->getCurrentTurnColour() == ChessGame::PLAYER_WHITE ? 'w' : 'b') . 'time ' . UCI_TIME_PER_MOVE_MS, true, false);
         stream_set_blocking($fromEngine, 1);
         while (stripos($move = trim(fgets($fromEngine)), 'bestmove') !== 0) {
             debug('<-- ' . $move);
             if (stripos($move, 'Seg') === 0) {
                 // Segfault
                 debug('UCI engine segfaulted?');
                 exit;
             }
         }
         debug('Move info: ', $move);
         $move = explode(' ', $move);