Esempio n. 1
0
     if (empty($resultChessCurrentMove)) {
         $modelGeneral->clearCache($queryChessCurrentMove, array($_SESSION['user']['id'], $_GET['id'], $move_id));
     }
     $curfen = $resultChessCurrentMove['move_fen'];
     $move = $resultChessCurrentMove['move'];
     $level = $resultChessCurrentMove['move_number'];
 } else {
     if (!empty($_GET['move']) && !empty($_GET['fen'])) {
         $curfen = $_GET['fen'];
     }
 }
 //pr($resultChess);
 //pr($resultChessMoves);
 //pr($resultChessCurrentMove);
 //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();
Esempio n. 2
0
<?php

ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . realpath('PEAR'));
require_once 'Connections/conn.php';
require_once 'Games/Chess/Standard.php';
include_once 'functions.php';
include_once 'Chess.class.php';
$standard = new Games_Chess_Standard();
$fen = !empty($_GET['fen']) ? $_GET['fen'] : '';
$standard->resetGame($fen);
$toMove = $standard->toMove();
$renderFen = $standard->renderFen();
if (empty($fen)) {
    //start of the game, find the first move:
    $chess = new Chess();
    $move = $chess->find($renderFen);
    $from = substr($move, 0, 2);
    $to = substr($move, 2, 2);
    $move2 = $standard->_convertSquareToSAN($from, $to);
    $standard->moveSquare($from, $to);
    $renderFen = $standard->renderFen();
    mysql_select_db($database_conn, $conn);
    $query_rsView = sprintf("SELECT * FROM games WHERE move = %s and fen = %s and moveby = %s", GetSQLValueString($move2, "text"), GetSQLValueString($renderFen, "text"), GetSQLValueString($toMove, "text"));
    $rsView = mysql_query($query_rsView, $conn) or die(mysql_error());
    $totalRows_rsView = mysql_num_rows($rsView);
    if ($totalRows_rsView == 0) {
        $query = sprintf("INSERT INTO games SET pid = 0, move = %s, fen = %s, moveby = %s, result = ''", GetSQLValueString($move2, "text"), GetSQLValueString($renderFen, "text"), GetSQLValueString($toMove, "text"));
        $rs = mysql_query($query, $conn) or die(mysql_error());
    }
}
echo 'done';
Esempio n. 3
0
<?php

require_once 'Connections/conn.php';
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . realpath('PEAR'));
require_once 'Games/Chess/Standard.php';
include_once 'functions.php';
include_once 'Chess.class.php';
$time1 = microtime(true);
$moves = trim($_GET['moves']);
$standard = new Games_Chess_Standard();
$standard->resetGame();
if (!empty($moves)) {
    $tmp = explode('.', $moves);
    $tmp = array_slice($tmp, 1);
    foreach ($tmp as $k => $v) {
        $mv = explode(' ', $v);
        $white = !empty($mv[0]) ? clean($mv[0], $standard) : '';
        $standard->moveSAN($white);
        //pr($standard->getMoveList());
        $black = !empty($mv[1]) ? clean($mv[1], $standard) : '';
        if ($black == '') {
            break;
        }
        $standard->moveSAN($black);
        //pr($standard->getMoveList());
    }
}
$fen = $standard->renderFen();
$moves = $standard->getMoveList();
$toMove = $standard->toMove();
$moveby = 'W';
Esempio n. 4
0
        $standard->moveSAN($white);
        //pr($standard->getMoveList());
        $black = !empty($mv[1]) ? clean($mv[1], $standard) : '';
        if ($black == '') {
            break;
        }
        //echo 'White: '.$white.', black: '.$black.'<br>';
        $standard->moveSAN($black);
        //pr($standard->getMoveList());
    }
    $fen = $standard->renderFen();
    $moves = $standard->getMoveList();
    $toMove = $standard->toMove();
}
if (!empty($_POST['MM_Insert']) && $_POST['MM_Insert'] == 'fenplay') {
    $standard = new Games_Chess_Standard();
    $standard->resetGame($_POST['fen']);
    $fen = $standard->renderFen();
    $moves = $standard->getMoveList();
    $toMove = $standard->toMove();
    $moveby = 'W';
    if ($toMove == 'W') {
        $moveby = 'B';
    }
    //check db if fen occurs:
    $chess = new Chess();
    $result = $chess->findfen($fen, 'finalgames');
    $legalMoves = array();
    if ($result[0] == 0) {
        $move = $chess->find($fen);
        $from = substr($move, 0, 2);
Esempio n. 5
0
 /**
  * Validate a move
  * @param array parsed move array from {@link _parseMove()}
  * @return true|PEAR_Error
  * @throws GAMES_CHESS_ERROR_MOVE_MUST_CAPTURE
  * @access protected
  */
 function _validMove($move)
 {
     list($type, $info) = each($move);
     if ($this->_capturePossible() && ($type == GAMES_CHESS_CASTLE || $this->_board[$info['square']] == $info['square'])) {
         if ($type == GAMES_CHESS_CASTLE) {
             $san = $info == 'K' ? 'O-O' : 'O-O-O';
         } else {
             $san = $info['piece'] . $info['disambiguate'] . $info['takes'] . $info['square'];
         }
         return $this->raiseError(GAMES_CHESS_ERROR_MOVE_MUST_CAPTURE, array('san' => $san));
     }
     return parent::_validMove($move);
 }
Esempio n. 6
0
$colid_rsView = "-1";
if (isset($_GET['id'])) {
    $colid_rsView = $_GET['id'];
}
mysql_select_db($database_conn, $conn);
$query_rsView = sprintf("SELECT * FROM games WHERE fen = %s OR id = %s", GetSQLValueString($colname_rsView, "text"), GetSQLValueString($colid_rsView, "int"));
$rsView = mysql_query($query_rsView, $conn) or die(mysql_error());
$row_rsView = mysql_fetch_assoc($rsView);
$totalRows_rsView = mysql_num_rows($rsView);
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . realpath('PEAR'));
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);
Esempio n. 7
0
<?php

include 'config.php';
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . '/Applications/MAMP/htdocs/chess/libraries/PEAR');
include_once 'Connections/conn.php';
require_once 'Games/Chess/Standard.php';
//rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
$standard = new Games_Chess_Standard();
$standard->resetGame();
echo $standard->renderFen();
echo '<br>';
$standard->moveSAN('f4');
$standard->moveSAN('e5');
$list = getlegalmoves($standard);
pr($list);
$standard->moveSAN('g4');
$standard->moveSAN('Qh4');
echo $standard->renderFen();
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);
Esempio n. 8
0
<?php

ob_start();
ini_set('memory_limit', '500M');
ini_set('max_execution_time', '-1');
include 'config.php';
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . '/Applications/MAMP/htdocs/chess/libraries/PEAR');
include_once 'Connections/conn.php';
require_once 'Games/Chess/Standard.php';
//rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1
$standard = new Games_Chess_Standard();
$standard->blankBoard();
$standard->addPiece('W', 'K', 'g5');
$standard->addPiece('W', 'Q', 'f5');
$standard->addPiece('B', 'K', 'g8');
//$standard->_move = 'B';
$initial = $standard->renderFen();
$fen_id = createposition($initial);
//$list = getlegalmoves($standard);
$rs = mysql_query("select * from gamesallmoves where fen_id = '" . $fen_id . "' order by id limit 1") or die(mysql_error());
if (mysql_num_rows($rs) == 0) {
    echo 'inserting first: ';
    insertgamesallmoves($standard, $initial, 0, $fen_id);
} else {
    echo 'inserting followup: ';
    $rs = mysql_query("select * from gamesallmoves where (result = '' or result is null) AND processed = 0 AND fen_id = '" . $fen_id . "' order by id limit 100") or die(mysql_error());
    if (mysql_num_rows($rs) == 0) {
        echo 'data completed';
    } else {
        while ($rec = mysql_fetch_array($rs)) {
            insertgamesallmoves($standard, $rec['fen'], $rec['id'], $fen_id);
Esempio n. 9
0
    }
    return $list;
}
function insert($standard, $list, $fen, $pid)
{
    foreach ($list as $move) {
        $standard->resetGame($fen);
        $toMove = $standard->toMove();
        $standard->moveSAN($move);
        $newfen = $standard->renderFen();
        echo $sql = "INSERT INTO `chess`.`games` (`move`, `moveby` , `fen`, `pid`) VALUES ('" . mysql_escape_string($move) . "', '" . $toMove . "', '" . mysql_escape_string($newfen) . "', '" . $pid . "')";
        echo '<br>';
        mysql_query($sql) or die(mysql_error());
    }
}
$standard = new Games_Chess_Standard();
$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);
Esempio n. 10
0
 function _validMove($move)
 {
     list($type, $info) = each($move);
     reset($move);
     if ($type == GAMES_CHESS_PIECEPLACEMENT) {
         if (!$this->_captured[$this->_move][$info['piece']]) {
             return $this->raiseError(GAMES_CHESS_ERROR_NOPIECES_TOPLACE, array('color' => $this->_move == 'W' ? 'B' : 'W', 'piece' => $info['piece']));
         }
         if ($this->_board[$info['square']] != $info['square']) {
             return $this->raiseError(GAMES_CHESS_ERROR_PIECEINTHEWAY, array('square' => $info['square']));
         }
         return true;
     } else {
         return parent::_validMove($move);
     }
 }