예제 #1
0
 public function process($standard, $fen)
 {
     $data = array();
     $data['fen'] = $fen;
     $toMove = $standard->toMove();
     $data['toMove'] = $toMove;
     $move = $this->find($fen);
     $from = substr($move, 0, 2);
     $to = substr($move, 2, 2);
     $move2 = $standard->_convertSquareToSAN($from, $to);
     $standard->moveSquare($from, $to);
     $renderFen = $standard->renderFen();
     $data['fenpost'] = $renderFen;
     $legalMoves = getlegalmoves($standard, $renderFen);
     $result = '';
     if (!empty($legalMoves['success']) && $legalMoves['success'] == 1) {
         $result = $legalMoves['result'];
     }
     $data['result'] = $result;
     $data['show'] = $move2;
     $data['ponder'] = $this->ponder;
     return $data;
 }
예제 #2
0
 //Game meta start
 $standard = new Games_Chess_Standard();
 $standard->resetGame($curfen);
 $fen = $standard->renderFen();
 $toMove = $standard->toMove();
 //Game meta end
 //moves in db
 $movesInDb = array();
 if (!empty($resultChessMoves)) {
     foreach ($resultChessMoves as $v) {
         $movesInDb[] = $v['move'];
     }
 }
 //moves in db ends
 //legal moves started
 $legalMoves = getlegalmoves($standard, $fen);
 $copyLegalMoves = array();
 if (!empty($legalMoves['success'])) {
     $copyLegalMoves = $legalMoves;
     $error = $legalMoves['result'];
     $msg = $legalMoves['msg'];
     $legalMoves = array();
 }
 //legal moves ended
 if ($toMove === 'W') {
     $level = $level + 1;
 }
 if (!empty($_GET['move'])) {
     $data = array();
     $data['repertory_id'] = $_GET['id'];
     $data['uid'] = $_SESSION['user']['id'];
예제 #3
0
$result = $chess->findfen($fen, 'finalgames_B');
$legalMoves = array();
if ($result[0] == 0) {
    $move = $chess->find($fen);
    $from = substr($move, 0, 2);
    $to = substr($move, 2, 2);
    $move2 = $standard->_convertSquareToSAN($from, $to);
    $show = $move2;
    $standard->moveSquare($from, $to);
    $renderFen = $standard->renderFen();
    $result = '';
    $process = 0;
    $legalMoves = getlegalmoves($standard, $renderFen);
    if (!empty($legalMoves['success']) && $legalMoves['success'] == 1) {
        $result = $legalMoves['result'];
        $process = 1;
    }
    //end if
    $query = sprintf("INSERT INTO finalgames_B SET move = %s, fen = %s, fenpost = %s, moveby = %s, result = %s, process = %s, played_by = 'Stockfish'", GetSQLValueString($move2, "text"), GetSQLValueString($fen, "text"), GetSQLValueString($renderFen, "text"), GetSQLValueString($toMove, "text"), GetSQLValueString($result, "text"), GetSQLValueString($process, "int"));
    $rs = @mysql_query($query, $conn);
} else {
    $renderFen = $result[1]['fenpost'];
    $move2 = $result[1]['move'];
    $show = $move2;
    $legalMoves = getlegalmoves($standard, $renderFen);
}
$time2 = microtime(true);
$return = array('moves' => $_GET['moves'], 'show' => $show, 'time' => $time2 - $time1 . ' secs');
$data = json_encode($return);
echo $_GET['jsoncallback'] . '(' . $data . ');';
exit;
예제 #4
0
function insertgamesallmoves($standard, $fen, $pid, $fen_id)
{
    $standard->resetGame($fen);
    $list = getlegalmoves($standard);
    foreach ($list as $move) {
        $cid = '';
        if (!empty($pid)) {
            $sql = "insert into gamesallmoves (`move_number` ,`fen_id` ,`fen` ,`move_by` ,`result` ,`move_w_1` ,`move_b_1` ,`move_w_2` ,`move_b_2` ,`move_w_3` ,`move_b_3` ,`move_w_4` ,`move_b_4` ,`move_w_5` ,`move_b_5` ,`move_w_6` ,`move_b_6` ,`move_w_7` ,`move_b_7` ,`move_w_8` ,`move_b_8` ,`move_w_9` ,`move_b_9` ,`move_w_10` ,`move_b_10` ,`move_w_11` ,`move_b_11` ,`move_w_12` ,`move_b_12` ,`move_w_13` ,`move_b_13` ,`move_w_14` ,`move_b_14` ,`move_w_15` ,`move_b_15` ,`move_w_16` ,`move_b_16` ,`move_w_17` ,`move_b_17` ,`move_w_18` ,`move_b_18` ,`move_w_19` ,`move_b_19` ,`move_w_20` ,`move_b_20`) select `move_number` ,`fen_id` ,`fen` ,`move_by` ,`result` ,`move_w_1` ,`move_b_1` ,`move_w_2` ,`move_b_2` ,`move_w_3` ,`move_b_3` ,`move_w_4` ,`move_b_4` ,`move_w_5` ,`move_b_5` ,`move_w_6` ,`move_b_6` ,`move_w_7` ,`move_b_7` ,`move_w_8` ,`move_b_8` ,`move_w_9` ,`move_b_9` ,`move_w_10` ,`move_b_10` ,`move_w_11` ,`move_b_11` ,`move_w_12` ,`move_b_12` ,`move_w_13` ,`move_b_13` ,`move_w_14` ,`move_b_14` ,`move_w_15` ,`move_b_15` ,`move_w_16` ,`move_b_16` ,`move_w_17` ,`move_b_17` ,`move_w_18` ,`move_b_18` ,`move_w_19` ,`move_b_19` ,`move_w_20` ,`move_b_20` from gamesallmoves WHERE id = " . $pid;
            mysql_query($sql) or die(mysql_error());
            $cid = mysql_insert_id();
        }
        $standard->resetGame($fen);
        $toMove = $standard->toMove();
        $standard->moveSAN($move);
        $newfen = $standard->renderFen();
        if (empty($cid)) {
            $movenumber = 1;
            $field = 'move_' . strtolower($toMove) . '_' . $movenumber;
            echo $sql = "INSERT INTO gamesallmoves set fen_id = '" . $fen_id . "', move_by = '" . $toMove . "', result = '" . $standard->gameOver() . "', " . $field . " = '" . mysql_escape_string($move) . "', fen = '" . mysql_escape_string($newfen) . "', move_number = " . $movenumber . ", pid = " . $pid;
        } else {
            $sql = "select * from gamesallmoves where id = '" . $pid . "'";
            $rs = mysql_query($sql) or die(mysql_error());
            $rec = mysql_fetch_array($rs);
            $movenumber = $rec['move_number'];
            if ($toMove === 'W') {
                $movenumber = $movenumber + 1;
            }
            $field = 'move_' . strtolower($toMove) . '_' . $movenumber;
            echo $sql = "UPDATE gamesallmoves set move_by = '" . $toMove . "', result = '" . $standard->gameOver() . "', " . $field . " = '" . mysql_escape_string($move) . "', fen = '" . mysql_escape_string($newfen) . "', move_number = " . $movenumber . ", pid = " . $pid . " where id = " . $cid;
        }
        echo '<br>';
        mysql_query($sql) or die(mysql_error());
    }
}
예제 #5
0
        if (!empty($legalMoves['success']) && $legalMoves['success'] == 1) {
            $result = $legalMoves['result'];
            $process = 1;
        }
        //end if
        $query = sprintf("INSERT INTO finalgames SET move = %s, fen = %s, fenpost = %s, moveby = %s, result = %s, process = %s, played_by = 'Stockfish', owner = %s", GetSQLValueString($move2, "text"), GetSQLValueString($fen, "text"), GetSQLValueString($renderFen, "text"), GetSQLValueString($toMove, "text"), GetSQLValueString($result, "text"), GetSQLValueString($process, "int"), GetSQLValueString($toMove, "text"));
        $rs = mysql_query($query, $conn) or die(mysql_error());
    } else {
        $renderFen = $result[1]['fenpost'];
        $move2 = $result[1]['move'];
        $legalMoves = getlegalmoves($standard, $renderFen);
    }
    if (empty($legalMoves['success'])) {
        foreach ($legalMoves as $k => $v) {
            $process = 0;
            $legalMoves2 = getlegalmoves($standard, $v['fen']);
            if (!empty($legalMoves2['success']) && $legalMoves2['success'] == 1) {
                $result = $legalMoves2['result'];
                $process = 1;
            }
            $query = sprintf("INSERT INTO finalgames SET move = %s, fen = %s, fenpost = %s, moveby = %s, result = %s, process = %s, owner = %s", GetSQLValueString($v['move'], "text"), GetSQLValueString($renderFen, "text"), GetSQLValueString($v['fen'], "text"), GetSQLValueString($moveby, "text"), GetSQLValueString($result, "text"), GetSQLValueString($process, "int"), GetSQLValueString($toMove, "text"));
            $rs = @mysql_query($query, $conn);
        }
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Main Page</title>
예제 #6
0
require_once 'Games/Chess/Standard.php';
include_once 'functions.php';
include_once 'Chess.class.php';
echo $query_rsView . '<br>';
pr($row_rsView);
$standard = new Games_Chess_Standard();
$fen = $row_rsView['fen'];
$standard->resetGame($fen);
$toMove = $standard->toMove();
echo $toMove;
echo '<br>';
$result = $standard->gameOver();
echo $result;
echo '<br>';
$result = !empty($result) ? $result : 'In Progress';
$legalMovesOriginal = getlegalmoves($standard, $fen);
echo $fen;
echo '<br>';
pr($legalMovesOriginal);
exit;
$standard = process($standard, $fromMove, $toMove, $legalMovesOriginal, $row_rsView, $fen);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Play Game</title>
</head>

<body>
<table border="1" cellspacing="0" cellpadding="5">
예제 #7
0
$prefen = !empty($_GET['prefen']) ? $_GET['prefen'] : NULL;
$id = getkey($prefen);
$options = array('cacheDir' => realpath('cache/') . '/', 'lifeTime' => 60 * 60 * 24 * 365 * 10);
$Cache_Lite = new Cache_Lite($options);
$data = $Cache_Lite->get($id);
if (!empty($data)) {
    $array = json_decode($data, 1);
    pr($array);
}
if (!empty($fen) && !empty($_GET['save'])) {
    $arr = array();
    $arr['fenpost'] = $fen;
    $arr['fen'] = !empty($_GET['prefen']) ? $_GET['prefen'] : NULL;
    $arr['toMove'] = !empty($_GET['toMove']) ? $_GET['toMove'] : NULL;
    $arr['show'] = !empty($_GET['move']) ? $_GET['move'] : NULL;
    $legalMoves = getlegalmoves($standard, $arr['fenpost']);
    $result = '';
    $process = 0;
    if (!empty($legalMoves['success']) && $legalMoves['success'] == 1) {
        $result = $legalMoves['result'];
        $process = 1;
    }
    $arr['result'] = $result;
    $arr['process'] = $process;
    $arr['ponder'] = NULL;
    $arr['time'] = '0 secs';
    if ($data = $Cache_Lite->get($id)) {
        $side = $arr['toMove'];
        replacemove($side, $data);
    } else {
        $arr = json_encode($arr);
예제 #8
0
function process($standard, $fromMove, $toMove, $legalMovesOriginal, $row_rsView, $fen)
{
    if ($fromMove == 'B') {
        $table = 'games';
    } else {
        $table = 'gamesblack';
    }
    global $database_conn, $conn;
    if ($toMove == $fromMove) {
        foreach ($legalMovesOriginal as $k => $v) {
            $renderFen = $v['fen'];
            $move2 = $v['move'];
            //checking result
            $result = '';
            $process = 0;
            $standard->moveSAN($move2);
            $legalMoves = getlegalmoves($standard, $renderFen);
            if (!empty($legalMoves['success']) && $legalMoves['success'] == 1) {
                $result = $legalMoves['result'];
                $process = 1;
            }
            //end if
            $standard->resetGame($fen);
            //end checking result
            mysql_select_db($database_conn, $conn);
            echo $query = sprintf("SELECT * FROM {$table} WHERE pid = %s and move = %s and fen = %s and moveby = %s", GetSQLValueString($row_rsView['id'], "int"), GetSQLValueString($move2, "text"), GetSQLValueString($renderFen, "text"), GetSQLValueString($toMove, "text"));
            echo '<br>';
            $rs = mysql_query($query, $conn) or die(mysql_error());
            $totalRows = mysql_num_rows($rs);
            if ($totalRows == 0) {
                echo $query = sprintf("INSERT INTO {$table} SET pid = %s, move = %s, fen = %s, moveby = %s, result = %s, process = %s", GetSQLValueString($row_rsView['id'], "int"), GetSQLValueString($move2, "text"), GetSQLValueString($renderFen, "text"), GetSQLValueString($toMove, "text"), GetSQLValueString($result, "text"), GetSQLValueString($process, "int"));
                echo '<br>';
                $rs = mysql_query($query, $conn) or die(mysql_error());
            }
        }
        $query = sprintf("UPDATE {$table} SET process = 1 WHERE id = %s", GetSQLValueString($row_rsView['id'], "int"));
        $rs = mysql_query($query, $conn) or die(mysql_error());
    } else {
        mysql_select_db($database_conn, $conn);
        echo $query = sprintf("SELECT * FROM {$table} WHERE pid = %s", GetSQLValueString($row_rsView['id'], "int"));
        echo '<br>';
        $rs = mysql_query($query, $conn) or die(mysql_error());
        $totalRows = mysql_num_rows($rs);
        if ($totalRows == 0) {
            $chess = new Chess();
            $move = $chess->find($row_rsView['fen']);
            $from = substr($move, 0, 2);
            $to = substr($move, 2, 2);
            $move2 = $standard->_convertSquareToSAN($from, $to);
            $standard->moveSquare($from, $to);
            $renderFen = $standard->renderFen();
            //checking result
            $result = '';
            $process = 0;
            $legalMoves = getlegalmoves($standard, $renderFen);
            if (!empty($legalMoves['success']) && $legalMoves['success'] == 1) {
                $result = $legalMoves['result'];
                $process = 1;
            }
            //end if
            $standard->resetGame($fen);
            //end checking result
            echo $query = sprintf("INSERT INTO {$table} SET pid = %s, move = %s, fen = %s, moveby = %s, result = %s, process = %s", GetSQLValueString($row_rsView['id'], "int"), GetSQLValueString($move2, "text"), GetSQLValueString($renderFen, "text"), GetSQLValueString($toMove, "text"), GetSQLValueString($result, "text"), GetSQLValueString($process, "int"));
            echo '<br>';
            $rs = mysql_query($query, $conn) or die(mysql_error());
        }
        $query = sprintf("UPDATE {$table} SET process = 1 WHERE id = %s", GetSQLValueString($row_rsView['id'], "int"));
        $rs = mysql_query($query, $conn) or die(mysql_error());
    }
    return $standard;
}
예제 #9
0
echo '<br>';
$list = getlegalmoves($standard);
pr($list);
exit;
$sql = "select * from games where processed = 0 ORDER BY id LIMIT 100";
$rs = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($rs) == 0) {
    $standard->resetGame();
    $pid = 0;
    $startfen = $standard->renderFen();
    $list = getlegalmoves($standard);
    //pr($list);
    insert($standard, $list, $startfen, $pid);
} else {
    while ($rec = mysql_fetch_array($rs)) {
        $standard->resetGame($rec['fen']);
        $pid = $rec['id'];
        $startfen = $standard->renderFen();
        $list = getlegalmoves($standard);
        //pr($list);
        insert($standard, $list, $startfen, $pid);
        mysql_query("update games set processed = 1 where id = " . $pid) or die(mysql_error());
    }
}
/*

			$promotemove = 0;
			if (strtoupper($loc) == 'P') {
				$promotemove = $standard->isPromoteMove($sq, $m);
			}
*/