Esempio n. 1
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. 2
0
 /**
  * Make a move from a Standard Algebraic Notation (SAN) format
  *
  * SAN is just a normal chess move like Na4, instead of the English Notation,
  * like NR4
  * @param string
  * @return true|PEAR_Error
  */
 function moveSAN($move)
 {
     if (!is_array($this->_board)) {
         $this->resetGame();
     }
     if (!strpos($move, '@')) {
         return parent::moveSAN($move);
     }
     if (!$this->isError($parsedMove = $this->_parseMove($move))) {
         if (!$this->isError($err = $this->_validMove($parsedMove))) {
             $p = $parsedMove[GAMES_CHESS_PIECEPLACEMENT]['piece'];
             $sq = $parsedMove[GAMES_CHESS_PIECEPLACEMENT]['square'];
             $this->_captured[$this->_move][$p]--;
             $set = $p == 'P' ? array($sq, 'P') : $sq;
             $this->_pieces[$this->_move][$p][] = $set;
             $this->_board[$sq] = $this->_move . $p . (count($this->_pieces[$this->_move][$p]) - 1);
             $this->_enPassantSquare = '-';
             $this->_moves[$this->_moveNumber][$this->_move == 'W' ? 0 : 1] = $move;
             $oldMoveNumber = $this->_moveNumber;
             $this->_moveNumber += $this->_move == 'W' ? 0 : 1;
             $this->_halfMoves++;
             $moveWithCheck = $move;
             if ($this->inCheckMate($this->_move == 'W' ? 'B' : 'W')) {
                 $moveWithCheck .= '#';
             } elseif ($this->inCheck($this->_move == 'W' ? 'B' : 'W')) {
                 $moveWithCheck .= '+';
             }
             $this->_movesWithCheck[$oldMoveNumber][$this->_move == 'W' ? 0 : 1] = $moveWithCheck;
             $this->_move = $this->_move == 'W' ? 'B' : 'W';
             // increment the position counter for this position
             $x = $this->renderFen(false);
             if (!isset($this->_allFENs[$x])) {
                 $this->_allFENs[$x] = 0;
             }
             $this->_allFENs[$x]++;
             return true;
         } else {
             return $err;
         }
     } else {
         return $parsedMove;
     }
 }