Esempio n. 1
0
                 $pgnString .= chr($rowG[fromCol] + 97);
             }
             /* check for captured pieces */
             if ($rowG[replaced] != "") {
                 if ($rowG[curPiece] == 'pawn') {
                     $pgnString .= chr($rowG[fromCol] + 97);
                 }
                 $pgnString .= "x";
             }
             #               else
             #                  $pgnString .= "-";
             /* destination square */
             $pgnString .= chr($rowG[toCol] + 97) . ($rowG[toRow] + 1);
             /* check for pawn promotion */
             if ($rowG[promotedTo] != "") {
                 $pgnString .= "=" . getPGNCode($rowG[promotedTo]);
             }
         }
         /* check for CHECK */
         if ($rowG[isInCheck]) {
             $pgnString .= "+";
         }
         /* if checkmate, $pgnString .= "#"; */
         $pgnString .= " ";
     }
     //add result
     $pgnString .= "{$situacao}";
 }
 //print pgn
 //   echo "$pgnString<br><br>";
 $nick = mysql_fetch_array(mysql_query("SELECT nick from players WHERE playerID='{$player}'"));
function moveToPGNString2($curColor, $piece, $fromRow, $fromCol, $toRow, $toCol, $pieceCaptured, $promotedTo, $isChecking)
{
    $pgnString = "";
    /* check for castling */
    if ($piece == "king" && abs($toCol - $fromCol) == 2) {
        /* if king-side castling */
        if ($toCol - $fromCol == 2) {
            $pgnString .= "O-O";
        } else {
            $pgnString .= "O-O-O";
        }
    } else {
        /* PNG code for moving piece */
        $pgnString .= getPGNCode($piece);
        /* source square */
        $pgnString .= chr($fromCol + 97) . ($fromRow + 1);
        /* check for captured pieces */
        if ($piece = 'pawn' && $fromCol != $toCol) {
            $pgnString .= "x";
        } else {
            if ($pieceCaptured != "") {
                $pgnString .= "x";
            } else {
                $pgnString .= "";
            }
        }
        /* destination square */
        $pgnString .= chr($toCol + 97) . ($toRow + 1);
        /* check for pawn promotion */
        if ($promotedTo != "") {
            $pgnString .= "=" . getPGNCode($promotedTo);
        }
    }
    /* check for CHECK */
    if ($isChecking) {
        $pgnString .= "+";
    }
    /* if checkmate, $pgnString .= "#"; */
    return $pgnString;
}
Esempio n. 3
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;
}