PHP Chess

Latest Stable Version Build Status License: GPL v3

A chess library for PHP.

Currently used on Redux Chess, which is a React chessboard connected to a PHP Chess server. Check out this demo.

Please note the sandbox server might not be up and running all the time.

Install

Via composer:

$ composer require chesslablab/php-chess

Play Chess

use Chess\Game;

$game = new Game();

$game->play('w', 'e4');
$game->play('b', 'e5');

The call to the $game->play method returns true or false depending on whether or not a chess move can be run on the board.

Play Chess With an AI

Pass the Game::MODE_AI parameter when instantiating a $game:

$game = new Game(Game::MODE_AI);

$game->play('w', 'e4');
$game->play('b', $game->response());
$game->play('w', 'e5');
$game->play('b', $game->response());

The AIs are stored in the model folder. The default is a1.model, if you want to play with a different AI pass it as a second parameter to the Chess\Game constructor:

$game = new Game(Game::MODE_AI, 'a2.model');

$game->play('w', 'e4');
$game->play('b', $game->response());
$game->play('w', 'e5');
$game->play('b', $game->response());

For further information you're invited to read my learning journey: