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
Installs: 7 539
Dependents: 3
Suggesters: 0
Security: 0
Stars: 14
Watchers: 7
Forks: 9
Open Issues: 2
Requires (Dev)
- johnkary/phpunit-speedtrap: ^1.0
- phpunit/phpunit: ^5.3
This package is not auto-updated.
Last update: 2020-03-20 17:26:42 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
Installation
use composer with composer require ryanhs/chess.php
or put in your composer.json
"require": {
"ryanhs/chess.php": "^1.0"
}
if you doesn't know composer, its a really usefull tools in php for package management,
try to learn composer here
Coding Style
about coding style, naming system.. because this is a PHP, i try to stick to use PHP-PSR, like game_over() become gameOver()
just keep in mind, any function name transformed into camelCase
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;
Chess.js
you can check original chess.js here
Chess.php documentation
you can check it here: https://ryanhs.github.io/chess.php
BUGS
TODO
MAINTAINER/COLLABORATOR NEEDED
As this project not in heavy development state, a maintainer/collaborator needed.
If you interested to become a collaborator, please tell me. :-)