Beispiel #1
0
 /**
  * @dataProvider dataProvider
  */
 public function testValidMove($fen, $moves)
 {
     $objChessGame = new ChessGame();
     $objChessGame->resetGame($fen);
     //        Should not be any exception here
     foreach ($moves as $objMoveData) {
         if ($objMoveData['white']) {
             $strCleanMove = $this->cleanSANMove($objMoveData['white']);
             $objChessGame->moveSAN($strCleanMove);
         }
         if ($objMoveData['black']) {
             $strCleanMove = $this->cleanSANMove($objMoveData['black']);
             $objChessGame->moveSAN($strCleanMove);
         }
     }
 }
Beispiel #2
0
<?php

require_once get_file_loc('ChessGame.class.inc');
$template->assignByRef('ChessGame', ChessGame::getChessGame($var['ChessGameID']));
$template->assign('ChessMoveHREF', SmrSession::getNewHREF(create_container('chess_move_processing.php', '', array('AJAX' => true, 'ChessGameID' => $var['ChessGameID']))));
<?php

require_once get_file_loc('ChessGame.class.inc');
$chessGame =& ChessGame::getChessGame($var['ChessGameID']);
$result = $chessGame->resign($player->getAccountID());
$container = create_container('skeleton.php');
if ($player->isLandedOnPlanet()) {
    $container['body'] = 'planet_main.php';
} else {
    $container['body'] = 'current_sector.php';
}
switch ($result) {
    case 0:
        $container['msg'] = '[color=green]Success:[/color] You have resigned from [chess=' . $var['ChessGameID'] . '].';
        break;
    case 1:
        $container['msg'] = '[color=green]Success:[/color] [chess=' . $var['ChessGameID'] . '] has been cancelled.';
        break;
}
forward($container);
Beispiel #4
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);
<?php

require_once get_file_loc('ChessGame.class.inc');
if (!is_numeric($_REQUEST['player_id'])) {
    create_error('You must select a player.');
}
ChessGame::insertNewGame(TIME, null, $player, SmrPlayer::getPlayerByPlayerID($_REQUEST['player_id'], $player->getGameID()));
forward(create_container('skeleton.php', 'chess.php'));
Beispiel #6
0
<?php

require_once '../htdocs/config.inc';
require_once LIB . 'Default/Globals.class.inc';
require_once get_file_loc('ChessGame.class.inc');
SmrSession::$game_id = 44;
$db = new SmrMySqlDatabase();
$db->query('DELETE FROM player_hof WHERE type LIKE \'Chess%\'');
$db->query('SELECT chess_game_id FROM chess_game');
while ($db->nextRecord()) {
    $chessGameID = $db->getInt('chess_game_id');
    $game =& ChessGame::getChessGame($chessGameID);
    echo 'Running game ' . $chessGameID . ' for white id "' . $game->getWhiteID() . '", black id "' . $game->getBlackID() . '", winner "' . $game->getWinner() . '"' . EOL;
    echoChessMoves($game);
    $game->rerunGame(true);
    echo 'Finished game ' . $chessGameID . ' for white id "' . $game->getWhiteID() . '", black id "' . $game->getBlackID() . '", winner "' . $game->getWinner() . '"' . EOL;
    echoChessMoves($game);
}
function echoChessMoves($game)
{
    echo 'Moves: ' . EOL;
    $moves = $game->getMoves();
    foreach ($moves as $move) {
        echo $move . EOL;
    }
    echo EOL;
}
Beispiel #7
0
<?php

require_once get_file_loc('ChessGame.class.inc');
$chessGames =& ChessGame::getOngoingAccountGames($player->getAccountID());
$template->assign('ChessGames', $chessGames);
$playersChallenged = array($player->getAccountID() => true);
foreach ($chessGames as $chessGame) {
    $playersChallenged[$chessGame->getWhiteID()] = true;
    $playersChallenged[$chessGame->getBlackID()] = true;
}
$players = array();
$db->query('SELECT player_id, player.player_name FROM player JOIN account USING(account_id) LEFT OUTER JOIN npc_logins USING(login) WHERE working IS NULL AND validated = ' . $db->escapeBoolean(true) . ' AND game_id = ' . $db->escapeNumber($player->getGameID()) . ' AND account_id NOT IN (' . $db->escapeArray(array_keys($playersChallenged)) . ') ORDER BY player_name');
while ($db->nextRecord()) {
    $players[$db->getInt('player_id')] = $db->getField('player_name');
}
$template->assignByRef('PlayerList', $players);
if (ENABLE_NPCS_CHESS) {
    $npcs = array();
    $db->query('SELECT player_id, player.player_name FROM player JOIN account USING(account_id) JOIN npc_logins USING(login) WHERE validated = ' . $db->escapeBoolean(true) . ' AND game_id = ' . $db->escapeNumber($player->getGameID()) . ' AND account_id NOT IN (' . $db->escapeArray(array_keys($playersChallenged)) . ') ORDER BY player_name');
    while ($db->nextRecord()) {
        $npcs[$db->getInt('player_id')] = $db->getField('player_name');
    }
    $template->assignByRef('NPCList', $npcs);
}
 private function getRandomGame($request)
 {
     $gameId = null;
     if (isset($request['databaseId'])) {
         $chessDb = new ChessDatabase($request['databaseId']);
         $gameId = $chessDb->getRandomGameId();
     }
     $gameObj = new ChessGame($gameId);
     return $gameObj->getJSON();
 }