PHP code example of p-chess / chess

1. Go to this page and download the library: Download p-chess/chess library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

p-chess / chess example snippets




Chess\Chess\Chess;
use \PChess\Chess\Output\UnicodeOutput;

$chess = new Chess();
while (!$chess->gameOver()) {
    $moves = $chess->moves();
    $move = $moves[random_int(0, count($moves) - 1)];
    $chess->move($move);
}

echo (new UnicodeOutput())->render($chess) . PHP_EOL;


// use...
$chess = new Chess();
echo (new AsciiOutput())->render($chess);


// use...
$chess = new Chess();
echo (new UnicodeOutput())->render($chess);


// use...
$chess = new Chess();
$imagine = new \Imagine\Gd\Imagine();   // or \Imagine\Imagick\Imagine()
$output = new ImageOutput($imagine, '/your/path/to/images', 480);
header('Content-Type: image/png');  
echo $output->render($chess);