phpChess :: (Daemon) barryd.it@gmail.com board)) { foreach (range('a', 'h') as $file) { foreach (range('1', '8') as $rank) { $this->board["$file$rank"] = "\x20"; } } $this->board = array_merge($this->board, $pieces); } else { return $this->board; } } public function evaluate() { } public function __construct() { /* * Populate the Chess Board w/ associated characters. */ $this->board( /* * Figurine Algebraic Notation */ array( 'a1' => "\xe2\x99\x96", 'b1' => "\xe2\x99\x98", 'c1' => "\xe2\x99\x97", 'd1' => "\xe2\x99\x95", 'e1' => "\xe2\x99\x94", 'f1' => "\xe2\x99\x97", 'g1' => "\xe2\x99\x98", 'h1' => "\xe2\x99\x96", 'a2' => "\xe2\x99\x99", 'b2' => "\xe2\x99\x99", 'c2' => "\xe2\x99\x99", 'd2' => "\xe2\x99\x99", 'e2' => "\xe2\x99\x99", 'f2' => "\xe2\x99\x99", 'g2' => "\xe2\x99\x99", 'h2' => "\xe2\x99\x99", 'a7' => "\xe2\x99\x99", 'b7' => "\xe2\x99\x99", 'c7' => "\xe2\x99\x99", 'd7' => "\xe2\x99\x99", 'e7' => "\xe2\x99\x99", 'f7' => "\xe2\x99\x99", 'g7' => "\xe2\x99\x99", 'h7' => "\xe2\x99\x99", 'a8' => "\xe2\x99\x9c", 'b8' => "\xe2\x99\x9e", 'c8' => "\xe2\x99\x9d", 'd8' => "\xe2\x99\x9b", 'e8' => "\xe2\x99\x9a", 'f8' => "\xe2\x99\x9d", 'g8' => "\xe2\x99\x9e", 'h8' => "\xe2\x99\x9c" ) ); } public function main() { } public function move($string) { } } /* White ♔ (king) ("\xe2\x99\x94") ♕ (queen) ("\xe2\x99\x95") ♖ (rook) ("\xe2\x99\x96") ♗ (bishop) ("\xe2\x99\x97") ♘ (knight) ("\xe2\x99\x98") ♙ (pawn) ("\xe2\x99\x99") Black ♚ (king) ("\xe2\x99\x9a") ♛ (queen) ("\xe2\x99\x9b") ♜ (rook) ("\xe2\x99\x9c") ♝ (bishop) ("\xe2\x99\x9d") ♞ (knight) ("\xe2\x99\x9e") ♟ (pawn) ("\xe2\x99\x9f") */ ?> * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ class player extends chess { public $player = array('stdin' => NULL); public function stdin() { $this->player['stdin']['read'][] = STDIN; stream_select($this->player['stdin']['read'], $this->player['stdin']['write'] = NULL, $this->player['stdin']['except'] = NULL, $this->player['stdin']['tv'] = 0); if (count($this->player['stdin']['read'])) { $this->player['stdin']['buffer'] = @fread(STDIN, 1500); switch($this->player['stdin']['buffer']) { case "\x0A": return "\x0A"; break; default: $this->player['stdin']['buffer'] = str_replace(array("\r", "\n"), "", $this->player['stdin']['buffer']); return $this->player['stdin']['buffer']; break; } } unset($this->player['stdin']); } function command($string) { switch($string) { case "test": return 'Testing your computer for virus scanner.'; break; case "quit": global $config; $config['run'] = false; return "Shutting down"; break; default: break; } } public function chessboard() { $chessboard = $this->board(); return << http://en.wikipedia.org/wiki/Descriptive_chess_notation Fédération Internationale des Échecs (World Chess Federation) http://en.wikipedia.org/wiki/FIDE http://en.wikipedia.org/wiki/Chess_problem http://en.wikipedia.org/wiki/Chess_problem_terminology http://en.wikipedia.org/wiki/Chessboard $chessboard = array(); foreach (range('a', 'h') as $file) { foreach (range('1', '8') as $rank) { $chessboard[$file$rank] = ''; } } print_r($chessboard); http://en.wikipedia.org/wiki/Fairy_chess_piece 16 Pieces White -> King(1), Queen(1), Rook(2), Bishop(2), Knight(2), Pawn(8) Black -> King(1), Queen(1), Rook(2), Bishop(2), Knight(2), Pawn(8) Files a b c d e f g h +---+---+---+---+---+---+---+---+ 1 | X | X | X | X | X | X | X | X | 1 +---+---+---+---+---+---+---+---+ 2 | X | X | X | X | X | X | X | X | 2 +---+---+---+---+---+---+---+---+ 3 | | | | | | | | | 3 R +---+---+---+---+---+---+---+---+ a 4 | | | | | | | | | 4 n +---+---+---+---+---+---+---+---+ k 5 | | | | | | | | | 5 s +---+---+---+---+---+---+---+---+ 6 | | | | | | | | | 6 +---+---+---+---+---+---+---+---+ 7 | X | X | X | X | X | X | X | X | 7 +---+---+---+---+---+---+---+---+ 8 | X | X | X | X | X | X | X | X | 8 +---+---+---+---+---+---+---+---+ a b c d e f g h http://www.rubyquiz.com/quiz35.html */ include('class.chess.php'); include('class.player.php'); $chess = new chess; $player = new player; while(1) { echo "\x1b\x5b\x58\x1b\x5b\x32\x4a"; echo $player->chessboard(); usleep(900); $tmp['stream'] = $player->stdin(); if ($tmp['stream'] != NULL) { if ($tmp['stream'] == "\n") { echo 'command # '; } else { if (($tmp['buffer'] = $player->command($tmp['stream']))) { echo $tmp['buffer'] . "\n"; } echo 'root@localhost:~ # '; } } exit(); } ?>