function createNewGame($game_id, $id960 = "") { global $mysql; $num_moves = -1; $query = "\n\t\tDELETE FROM " . T_HISTORY . "\n\t\tWHERE h_game_id = '{$_SESSION['game_id']}'\n\t"; $mysql->query($query, __LINE__, __FILE__); $pos = id960_to_pos($id960); // (chessutils.inc.php) $initFEN = strtolower($pos) . "/pppppppp/8/8/8/8/PPPPPPPP/{$pos} w KQkq - 0 1"; $query = "\n\t\tINSERT INTO " . T_HISTORY . "\n\t\t\t(h_time, h_game_id, h_fen)\n\t\tVALUES\n\t\t\t(NOW( ), '{$_SESSION['game_id']}', '{$initFEN}')\n\t"; $mysql->query($query, __LINE__, __FILE__); initBoard($pos); }
if ($_SESSION['white']['p_username'] == $_SESSION['username']) { $_SESSION['player'] =& $_SESSION['white']; $_SESSION['player']['p_color'] = 'white'; $_SESSION['opponent'] =& $_SESSION['black']; $_SESSION['opponent']['p_color'] = 'black'; } else { $_SESSION['player'] =& $_SESSION['black']; $_SESSION['player']['p_color'] = 'black'; $_SESSION['opponent'] =& $_SESSION['white']; $_SESSION['opponent']['p_color'] = 'white'; } // get id960 and position $query = "\n\t\tSELECT g_id960\n\t\tFROM " . T_GAME . "\n\t\tWHERE g_id = '{$_SESSION['game_id']}'\n\t"; $_SESSION['id960'] = $mysql->fetch_value($query, __LINE__, __FILE__); } $initpos = id960_to_pos($_SESSION['id960']); $promoting = false; // init the promotion flag $undoing = false; // init the undo flag // get FEN array (this should probably be in an include somewhere) $i = 0; $query = "\n\tSELECT h_fen\n\tFROM " . T_HISTORY . "\n\tWHERE h_game_id = '{$_SESSION['game_id']}'\n\tORDER BY h_time\n"; $FENarray = $mysql->fetch_value_array($query, __LINE__, __FILE__); $num_moves = count($FENarray) - 1; // remove one for initpos loadGame(); // sets up board using last entry in ".T_HISTORY." table (chessdb.inc.php) FENtomoves(); // creates movesArray from FENarray (chessutils.inc.php) // find out if it's the current player's turn
// convert the current FEN array to an array of standard moves $num_moves = count($FENarray) - 1; // remove one for initpos FENtomoves(); // (chessutils.inc.php) // get White's username $query = "\n\t\tSELECT p_username\n\t\tFROM " . T_PLAYER . "\n\t\t\t, " . T_GAME . "\n\t\tWHERE " . T_PLAYER . ".p_id = " . T_GAME . ".g_white_player_id\n\t\t\tAND " . T_GAME . ".g_id = '{$_SESSION['game_id']}'\n\t"; $white_username = $mysql->fetch_value($query, __LINE__, __FILE__); // get Black's username $query = "\n\t\tSELECT p_username\n\t\tFROM " . T_PLAYER . "\n\t\t\t, " . T_GAME . "\n\t\tWHERE " . T_PLAYER . ".p_id = " . T_GAME . ".g_black_player_id\n\t\t\tAND " . T_GAME . ".g_id = '{$_SESSION['game_id']}'\n\t"; $black_username = $mysql->fetch_value($query, __LINE__, __FILE__); // get id960 and position $query = "\n\t\tSELECT g_id960\n\t\tFROM " . T_GAME . "\n\t\tWHERE g_id = '{$_SESSION['game_id']}'\n\t"; $id960 = $mysql->fetch_value($query, __LINE__, __FILE__); $_SESSION['id960'] = $id960; $initpos = id960_to_pos($id960); // load players $players = "{$white_username} vs {$black_username}"; } // create a default player color $_SESSION['player']['p_color'] = 'white'; // convert the current FEN array to an array of standard moves FENtomoves(); // (chessutils.inc.php) //*/ $head_extra = ' <script type="text/javascript">//<![CDATA[ var watchgame = true; function redo( ) { window.location.replace("watchgame.php");