public static function check($input) { if (strlen($input) > 0) { $list = self::genList($input, false); } else { $list = self::genList("AA1121314151617181122232425262728217273747576777871828384858687888000000", false); } $cnt = 0; for ($i = 0; $i < count($list); $i++) { if (self::kingKillable($list[$i]) == false) { $cnt++; if ($cnt > 1) { return "Moves Available\n"; } else { $rec = explode(',', $list[$i]); $oneboard = $rec[3]; } } } if ($cnt == 1) { return "One:" . $oneboard . "\n"; } $board = new ChessBoard(); $board->loadString($input); $board->changeTurn(); $revboard = "Test,00,00," . $board->toString(); if (self::kingKillable($revboard)) { return "Checkmate\n"; } else { return "Stalemate\n"; } }
public function nextMove($input) { $moves = ChessBoard::moves($input); $bestscore = -1000000; $best = array(); $mult = substr($input, 0, 2) == "BB" ? -1 : 1; foreach ($moves as $movestring) { $movestring = explode(',', $movestring); $movestring = $movestring[3]; $score = $mult * $this->weigh($movestring); if ($score > $bestscore) { $bestscore = $score; $best = [$movestring]; } else { if ($score == $bestscore) { $best[] = $movestring; } } } return $best[rand(0, count($best) - 1)]; }
<?php $page_title = 'Documentation'; $active_nav_tab = 'Docs'; include APP_PATH . 'pages/header.php'; $examples = ChessBoard::getExamples(); $docs = ChessBoard::getDocs(); ?> <div class="section"> <h2 id="config">Config</h2> <table cellspacing="0"> <thead class="center"> <tr> <th>Property / Type</th> <th>Required</th> <th>Default</th> <th>Description</th> <th>Example</th> </tr> </thead> <tbody> <?php foreach ($docs['Config Object'] as $prop) { echo buildPropRow('config', $prop, $examples); } ?> </tbody> </table> </div><!-- end div.section -->
require APP_PATH . 'pages/home.php'; die; } // docs if ($URI[0] === 'docs') { require APP_PATH . 'pages/docs.php'; die; } // examples if ($URI[0] === 'examples' && $URI[1] === '') { require APP_PATH . 'pages/examples.php'; die; } // single example if ($URI[0] === 'examples' && $URI[1] !== '') { $example = ChessBoard::getExample($URI[1]); if ($example !== false) { require APP_PATH . 'pages/single_example.php'; die; } } // download if ($URI[0] === 'download') { require APP_PATH . 'pages/download.php'; die; } // license if ($URI[0] === 'license') { // just redirect them to the GitHub page for now header('HTTP/1.1 307 Temporary Redirect'); header('Location: https://github.com/oakmac/chessboardjs/blob/master/LICENSE.md');
public function generatePreList() { $temp = new ChessBoard(); $aboard = new ChessBoard(); $moves = array(); $output = array(); $moves[] = array(1, -1); $moves[] = array(1, 0); $moves[] = array(1, 1); $moves[] = array(-1, 1); $moves[] = array(-1, -1); $moves[] = array(-1, 0); $moves[] = array(0, 1); $moves[] = array(0, -1); foreach ($moves as $move) { $output = array_merge($output, $this->addBoard($this->x, $this->y, $move)); } //the rest is castling conditions if ($this->typecode == ChessBoard::$WHITEKING) { //white king castling to the left if ($this->x == 5 && $this->y == 1 && $this->board->get(4, 1) == -1 && $this->board->get(3, 1) == -1 && $this->board->get(2, 1) == -1 && $this->board->get(1, 1) == ChessBoard::$WHITEROOK && !($this->board->castleData() & 64) && !($this->board->castleData() & 32)) { $aboard->copy($this->board); $aboard->changeTurn(); if ($this->recurse && !kingKillable("k,1,1," + $aboard->toString()) && !leftCastleThroughCheck($this->board)) { $temp->copy($this->board); $temp->set(1, 1, -1); $temp->set(3, 1, ChessBoard::$WHITEKING); $temp->set(4, 1, ChessBoard::$WHITEROOK); $temp->set(5, 1, -1); $temp->setLastMove(5, 1, 3, 1); $temp->changeTurn(); $temp->checkKingRookHome(); $output[] = $temp->toString(); } } // white king castling to the right if ($this->x == 5 && $this->y == 1 && $this->board->get(6, 1) == -1 && $this->board->get(7, 1) == -1 && $this->board->get(8, 1) == ChessBoard::$WHITEROOK && !($this->board->castleData() & 64) && !($this->board->castleData() & 16)) { $aboard->copy($this->board); $aboard->changeTurn(); if ($this->recurse && !kingKillable("k,1,1," + $aboard->toString()) && !rightCastleThroughCheck($this->board)) { $temp->copy($this->board); $temp->set(8, 1, -1); $temp->set(7, 1, ChessBoard::$WHITEKING); $temp->set(6, 1, ChessBoard::$WHITEROOK); $temp->set(5, 1, -1); $temp->setLastMove(5, 1, 7, 1); $temp->changeTurn(); $temp->checkKingRookHome(); $output[] = $temp->toString(); } } } if ($this->typecode == ChessBoard::$BLACKKING) { // black king castling to the left if ($this->x == 5 && $this->y == 8 && $this->board->get(4, 8) == -1 && $this->board->get(3, 8) == -1 && $this->board->get(2, 8) == -1 && $this->board->get(1, 8) == ChessBoard::$BLACKROOK && !($this->board->castleData() & 4) && !($this->board->castleData() & 2)) { $aboard->copy($this->board); $aboard->changeTurn(); if ($this->recurse && !kingKillable("k,1,1," + $aboard->toString()) && !leftCastleThroughCheck($this->board)) { $temp->copy($this->board); $temp->set(1, 8, -1); $temp->set(3, 8, ChessBoard::$BLACKKING); $temp->set(4, 8, ChessBoard::$BLACKROOK); $temp->set(5, 8, -1); $temp->setLastMove(5, 8, 3, 8); $temp->changeTurn(); $temp->checkKingRookHome(); $output[] = $temp->toString(); } } // black king castling to the right if ($this->x == 5 && $this->y == 8 && $this->board->get(6, 8) == -1 && $this->board->get(7, 8) == -1 && $this->board->get(8, 8) == ChessBoard::$BLACKROOK && !($this->board->castleData() & 4) && !($this->board->castleData() & 1)) { $aboard->copy($this->board); $aboard->changeTurn(); if ($this->recurse && !kingKillable("k,1,1," + $aboard->toString()) && !rightCastleThroughCheck($this->board)) { $temp->copy($this->board); $temp->set(8, 8, -1); $temp->set(7, 8, ChessBoard::$BLACKKING); $temp->set(6, 8, ChessBoard::$BLACKROOK); $temp->set(5, 8, -1); $temp->setLastMove(5, 8, 7, 8); $temp->changeTurn(); $temp->checkKingRookHome(); $output[] = $temp->toString(); } } } return $output; }
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title><?php echo PROJECT_NAME; if (isset($page_title)) { echo ' » ' . $page_title; } ?> </title> <base href="<?php echo BASE_URL; ?> " /> <meta name="viewport" content="width=device-width"> <link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon" /> <link rel="stylesheet" href="css/normalize-2.1.2.min.css" /> <link rel="stylesheet" href="css/foundation-3.2.5.min.css" /> <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:regular,semibold|Droid+Sans+Mono" /> <link rel="stylesheet" href="css/site.css" /> <link rel="stylesheet" href="css/chessboard.css" /> </head> <body> <?php if (isset($active_nav_tab)) { echo ChessBoard::buildTopBar($active_nav_tab); } ?> <div class="row" id="body_container"> <div class="twelve columns">
function newMoves(){ try{ console.log('refreshing'); }catch(e){ } chessObj.refreshListOfGames(); } </script> </head> <body> <?php include "chess-board.class.php"; $chessBoard = new ChessBoard(); $chessBoard->setPgn('dgt.pgn'); $chessBoard->setCss(array('bgColor' => '#7fb2e5', 'bgColorPlayers' => '#53a6d7', 'bgColorMoves' => '#bcd2fe', 'bgColorClock' => '#95c1d5')); $chessBoard->setJavascript(array('liveupdateinterval' => 15, 'serverFile' => 'chess.php', 'layout' => array('colorLightSquares' => '#e7f1fa', 'colorDarkSquares' => '#a2bdd9'), 'behaviour' => array('animationTime' => 0.3, 'autoplay' => array('delay' => 1)), 'listeners' => "{'loadgame' : showDetails, 'liveupdate' : receiveLiveUpdate, 'liveupdatenewmoves' : newMoves }")); $chessBoard->write(); // Another method for adding listeners // $chessBoard->addListeners("{'loadgame' : showDetails, 'liveupdate' : receiveLiveUpdate }"); ?> <h4>chess-board-class.php demo</h4> <p>This is a demo of how you can create a chess board using the chess-board-class.php file. </p> <p>Code used:</p> <h5>Simple example</h5> <p class="inline_code"> <?php include("chess-board.class.php");
<?php $page_title = 'Examples'; $active_nav_tab = 'Examples'; include APP_PATH . 'pages/header.php'; $examples = ChessBoard::getExamples(); $examplesGroups = ChessBoard::getExampleGroups(); ?> <div class="row"> <div class="three columns"> <div id="examples_list_container"> <?php echo buildExamplesList($examplesGroups, $examples); ?> </div><!-- end #examples_list --> </div><!-- end .three.columns --> <div class="nine columns"> <h2 id="example_name"></h2> <p><a href="#" id="example_single_page_link" target="_blank">View example in new window.</a></p> <p id="example_desc_container"></p> <div id="example_html_container"></div> <h4>JavaScript</h4> <div id="example_js_container"></div> <h4>HTML</h4> <div id="example_show_html_container"></div> </div> </div><!-- end div.row -->
<?php $page_title = 'Download'; $active_nav_tab = 'Download'; include APP_PATH . 'pages/header.php'; $releases = ChessBoard::getReleases(); $mostRecentVersion = $releases[0]['version']; ?> <div class="section"> <h1>Downloads</h1> <a class="button large radius" href="releases/<?php echo $mostRecentVersion; ?> /chessboardjs-<?php echo $mostRecentVersion; ?> .zip" style="line-height: 22px"> Download Most Recent Version<br /> <small style="font-weight: normal; font-size: 12px">v<?php echo $mostRecentVersion; ?> </small> </a> </div> <?php foreach ($releases as $release) { if (array_key_exists('released', $release) === true && $release['released'] === false) { continue; }