This project is a fork of ryanhs/chess.php, which is abandonned. chess.php itself was a port of chess.js. Main changes compared to the original ryanhs project are:
- It is compatible with PHP 8.1.
- PHP Unit has been updated to version 9
- The documentation has been imported right in the project
chess.php is a PHP chess library that is used for chess move generation/validation, piece placement/movement, and check/checkmate/stalemate detection - basically everything but the AI.
NOTE: this is a port of chess.js for php
composer require aglaia-resident/chess.php
The code below plays a complete game of chess ... randomly.
<?php
require 'vendor/autoload.php';
use \Ryanhs\Chess\Chess;
$chess = new Chess();
while (!$chess->gameOver()) {
$moves = $chess->moves();
$move = $moves[mt_rand(0, count($moves) - 1)];
$chess->move($move);
}
echo $chess->ascii() . PHP_EOL;