akondas / 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
v1.0.5
2019-01-28 22:14 UTC
Requires
- php: ^7.2
- ext-json: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.14
- johnkary/phpunit-speedtrap: ^3.0
- phpbench/phpbench: ^0.15.0
- phpstan/phpstan: ^0.11.1
- phpunit/phpunit: ^7.5
This package is auto-updated.
Last update: 2024-11-29 05:39:11 UTC
README
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, froked from ryanhs/chess.php
Installation
use composer with composer require akondas/chess.php
or put in your composer.json
"require": {
"ryanhs/chess.php": "^1.0"
}
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;
+------------------------+
8 | . . . . . . . . |
7 | . . . . r . . . |
6 | . . . . . . . . |
5 | . . . . . . . . |
4 | k . . . . . . . |
3 | . . . . . . K . |
2 | . . . n . . . . |
1 | . . . . . . . . |
+------------------------+
a b c d e f g h
Performance
There is still a lot to do in this topic.
akondas/php-grandmaster is a good place to start experiment ;)