Beispiel #1
0
                 //Calculate white player
                 $wnewpoints = $oR3DCQuery->ELOCalculation($wcurpoints, $bcurpoints, 0.5, 1, $oR3DCQuery->GetPlayerGameCount($w_player_id));
                 //update points
                 $oR3DCQuery->ELOUpdateRating($b_player_id, $bnewpoints);
                 $oR3DCQuery->ELOUpdateRating($w_player_id, $wnewpoints);
             }
             ///////////////////////////////////////////////////////////////////////
             $oR3DCQuery->UpdateGameStatus($config, $_GET['gameid'], "C", "D");
             $bmove_error = false;
             $oR3DCQuery->CachePlayerPointsByPlayerID($b_player_id);
             $oR3DCQuery->CachePlayerPointsByPlayerID($w_player_id);
         }
     }
 } else {
     $bmove_error = true;
     if (set_FEN($fen)) {
         $initiator = "";
         $w_player_id = "";
         $b_player_id = "";
         $status = "";
         $completion_status = "";
         $start_time = "";
         $next_move = "";
         $oR3DCQuery->GetGameInfoByRef($config, $_GET['gameid'], $initiator, $w_player_id, $b_player_id, $status, $completion_status, $start_time, $next_move);
         //checkmate
         if (get_GameState() == 1) {
             //if($w_player_id == $player_id){
             if ($next_move == 'w') {
                 ///////////////////////////////////////////////////////////////////////
                 //ELO Point Calculation
                 if ($oR3DCQuery->ELOIsActive() && $oR3DCQuery->IsGameRated($_GET['gameid'])) {
Beispiel #2
0
function writePGN()
{
    require 'connectdb.php';
    global $_SESSION, $history, $numMoves, $pWhite, $pWhiteF, $pWhiteL, $pBlack, $pBlackF, $pBlackL, $gStart;
    global $simplemove, $isDraw, $move_turn, $move_PlyNumber;
    $FEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
    set_FEN($FEN);
    #get_current_Position();
    #return;
    $xheader = "[Event \"WebChess Board #{$_SESSION['gameID']}\"]\n";
    $xheader .= "[Site \"WebChess\"]\n";
    $xheader .= "[Date \"{$gStart}\"]\n";
    $xheader .= "[Round \"-\"]\n";
    $xheader .= "[White \"{$pWhiteL}, {$pWhiteF}\"]\n";
    $xheader .= "[Black \"{$pBlackL}, {$pBlackF}\"]\n";
    $body = "";
    $bodyLine = "";
    for ($i = 0; $i <= $numMoves; $i += 2) {
        // White's move
        $token = "" . ($i / 2 + 1) . ".";
        if (strlen($bodyLine) + strlen($token) > 79) {
            $body .= $bodyLine . "\n";
            $bodyLine = "";
        } elseif (strlen($bodyLine) > 0) {
            $bodyLine .= " ";
        }
        $bodyLine .= $token;
        $tmpPromotedTo = "";
        if (!is_null($history[$i]['promotedTo'])) {
            $tmpPromotedTo = $history[$i]['promotedTo'];
        }
        $tmpCheck = $history[$i]['isInCheck'] == 1;
        $fr = $history[$i]['fromRow'];
        $fc = $history[$i]['fromCol'];
        $tr = $history[$i]['toRow'];
        $tc = $history[$i]['toCol'];
        $fs = coordsToSquare($fr, $fc);
        $ts = coordsToSquare($tr, $tc);
        #echo "<hr>Adding Move:$fs-$ts$tmpPromotedTo<hr>";
        add_Move("{$fs}-{$ts}" . getPGNCode($tmpPromotedTo));
        #echo get_current_Position();
        $token = $simplemove;
        if (strlen($bodyLine) + strlen($token) > 79) {
            $body .= $bodyLine . "\n";
            $bodyLine = "";
        } elseif (strlen($bodyLine) > 0) {
            $bodyLine .= " ";
        }
        $bodyLine .= $token;
        if ($i != $numMoves) {
            // Black's move
            $tmpPromotedTo = "";
            if (!is_null($history[$i + 1]['promotedTo'])) {
                $tmpPromotedTo = $history[$i + 1]['promotedTo'];
            }
            $tmpCheck = $history[$i + 1]['isInCheck'] == 1;
            $fr = $history[$i + 1]['fromRow'];
            $fc = $history[$i + 1]['fromCol'];
            $tr = $history[$i + 1]['toRow'];
            $tc = $history[$i + 1]['toCol'];
            $fs = coordsToSquare($fr, $fc);
            $ts = coordsToSquare($tr, $tc);
            #echo "<hr>Adding Move:$fs-$ts$tmpPromotedTo<hr>";
            add_Move("{$fs}-{$ts}" . getPGNCode($tmpPromotedTo));
            #echo get_current_Position();
            $token = $simplemove;
            if (strlen($bodyLine) + strlen($token) > 79) {
                $body .= $bodyLine . "\n";
                $bodyLine = "";
            } elseif (strlen($bodyLine) > 0) {
                $bodyLine .= " ";
            }
            $bodyLine .= $token;
        }
    }
    /* getResult() returns only definitive wins and remis.
     * If a player resigns, this is not reflected in it, so we need to check
     */
    $result = getResult();
    if ($isDraw) {
        $result = "1/2-1/2";
    }
    $tmpQuery = "SELECT gameMessage, messageFrom FROM " . $CFG_TABLE[games] . " WHERE gameID = " . $_SESSION['gameID'];
    $tmpMessages = mysql_query($tmpQuery);
    $tmpMessage = mysql_fetch_array($tmpMessages, MYSQL_ASSOC);
    if ($tmpMessage['gameMessage'] == "playerResigned") {
        if ($tmpMessage['messageFrom'] == "white") {
            $result = "0-1";
        } else {
            $result = "1-0";
        }
    }
    $body .= $bodyLine;
    if (strlen($bodyLine) + strlen($result) > 79) {
        $body .= "\n";
    } elseif (strlen($bodyLine) > 0) {
        $body .= " ";
    }
    $body .= $result . "\n\n";
    $xheader .= "[Result \"{$result}\"]\n\n";
    echo $xheader;
    echo $body;
}