aglaia-resident/chess.php

Fork of ryanhs/chess.php. 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

v2.2.0 2022-06-21 21:41 UTC

This package is auto-updated.

Last update: 2024-04-22 01:20:09 UTC


README

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

Installation

composer require aglaia-resident/chess.php

Example Code

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;

Documentation Summary

Common

FEN

MISC

MOVE

PGN

PIECE PLACEMENT

STATUS