$standard->resetGame($fen); $toMove = $standard->toMove(); $fen = $standard->renderFen(); echo 'fen: ' . $fen . '<br>'; $moveby = 'W'; if ($toMove == 'W') { $moveby = 'B'; } pr($rs); if ($toMove == 'B') { $legalMoves = getlegalmoves($standard, $fen); pr($legalMoves); if (empty($legalMoves['success'])) { $result = $chess->findfen($fen, 'finalgames_B'); 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; echo $query = sprintf("INSERT INTO finalgames_B SET move = %s, fen = %s, fenpost = %s, moveby = %s, played_by = 'Stockfish'", GetSQLValueString($move2, "text"), GetSQLValueString($fen, "text"), GetSQLValueString($renderFen, "text"), GetSQLValueString($toMove, "text")); echo '<br>'; $res = @mysql_query($query, $conn); if ($rs[0] > 0) { echo $query = sprintf("UPDATE finalgames_B SET process = 1 WHERE id = %s", GetSQLValueString($rs[1]['id'], "int")); echo '<br>'; $res = @mysql_query($query, $conn);
<?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';
<?php include 'Chess.class.php'; $Chess = new Chess(); echo $Chess->find('r1bq4/1p4kp/3p1n2/5pB1/p1pQ4/8/1P4PP/4RRK1 w - - 0 1'); exit; echo '<pre>'; file_put_contents('/Users/naveen/Downloads/stockfish-231-mac/Mac/fen.txt', 'r1bq4/1p4kp/3p1n2/5pB1/p1pQ4/8/1P4PP/4RRK1 w - - 0 1'); exec("/Users/naveen/Downloads/stockfish-231-mac/Mac/stockfish-231-64 bench 128 1 20 /Users/naveen/Downloads/stockfish-231-mac/Mac/fen.txt depth\n", $output, $returnvar); print_r($output); echo $subject = $output[count($output) - 1]; echo '<br>'; $match = preg_match('/^bestmove (.*) ponder (.*)$/siu', $subject, $matches); $move = !empty($matches[1]) ? $matches[1] : 'Not Found'; echo $move; exit; $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("file", "/tmp/error-output.txt", "a")); $cwd = '/Users/naveen/Downloads/stockfish-231-mac/Mac/'; $env = array('some_option' => 'aeiou'); $process = proc_open('stockfish-231-64', $descriptorspec, $pipes, $cwd, $env); if (is_resource($process)) { // $pipes now looks like this: // 0 => writeable handle connected to child stdin // 1 => readable handle connected to child stdout // Any error output will be appended to /tmp/error-output.txt fwrite($pipes[0], "uci\nisready\nposition startpos moves d2d4 e7e6\ngo depth 20\n"); fclose($pipes[0]); $x = stream_get_contents($pipes[1]); fclose($pipes[1]); fwrite('/Users/naveen/Downloads/stockfish-231-mac/Mac/tmp.txt', $x); print_r($x);
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; }
echo $query = sprintf("INSERT INTO gamespos 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 gamespos 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 gamespos 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);