The Chess\Board class is essentially a chess board representation that allows to play a game of chess in Portable Game Notation (PGN) format. It is the cornerstone that allows to build multiple features on top of it: FEN string generation, ASCII representation, PNG image creation, position evaluation, and many more cool features.

Let's look at some relevant Chess\Board methods available through the following example:

use Chess\Board;
use Chess\PGN\Convert;

$board = new Board();

$board->play(Convert::toStdObj('w', 'e4'));
$board->play(Convert::toStdObj('b', 'd5'));
$board->play(Convert::toStdObj('w', 'exd5'));
$board->play(Convert::toStdObj('b', 'Qxd5'));

getCaptures(): array

Gets the pieces captured by both players as an array of stdClass objects.

$captures = $board->getCaptures();

var_export($captures);

Output:

array (
  'w' =>
  array (
    0 =>
    (object) array(
       'capturing' =>
      (object) array(
         'identity' => 'P',
         'position' => 'e4',
      ),
       'captured' =>
      (object) array(
         'identity' => 'P',
         'position' => 'd5',
      ),
    ),
  ),
  'b' =>
  array (
    0 =>
    (object) array(
       'capturing' =>
      (object) array(
         'identity' => 'Q',
         'position' => 'd8',
      ),
       'captured' =>
      (object) array(
         'identity' => 'P',
         'position' => 'd5',
      ),
    ),
  ),
)

getCastling(): ?array

Gets the castling status.

$castling = $board->getCastling();

var_export($castling);
array (
  'w' =>
  array (
    'castled' => false,
    'O-O' => true,
    'O-O-O' => true,
  ),
  'b' =>
  array (
    'castled' => false,
    'O-O' => true,
    'O-O-O' => true,
  ),
)

getHistory(): array

Gets the history as an array of stdClass objects.

$history = $board->getHistory();

var_export($history);

Output:

array (
  0 =>
  (object) array(
     'pgn' => 'e4',
     'color' => 'w',
     'identity' => 'P',
     'position' => 'e2',
     'isCapture' => false,
     'isCheck' => false,
  ),
  1 =>
  (object) array(
     'pgn' => 'd5',
     'color' => 'b',
     'identity' => 'P',
     'position' => 'd7',
     'isCapture' => false,
     'isCheck' => false,
  ),
  2 =>
  (object) array(
     'pgn' => 'exd5',
     'color' => 'w',
     'identity' => 'P',
     'position' => 'e4',
     'isCapture' => true,
     'isCheck' => false,
  ),
  3 =>
  (object) array(
     'pgn' => 'Qxd5',
     'color' => 'b',
     'identity' => 'Q',
     'position' => 'd8',
     'isCapture' => true,
     'isCheck' => false,
  ),
)

getMovetext(): string

Gets the movetext in text format.

$movetext = $board->getMovetext();

var_export($movetext);

Output:

'1.e4 d5 2.exd5 Qxd5'

getTurn(): string

Gets the current turn.

$turn = $board->getTurn();

var_export($turn);

Output:

'w'

isCheck(): bool

Finds out if a player is in check.

$isCheck = $board->isCheck();

var_export($isCheck);

Output:

false

isMate(): bool

Finds out if a player is checkmated.

$isMate = $board->isMate();

var_export($isMate);

Output:

false

play(\stdClass $move): bool

Plays a chess move.

$board->play(Convert::toStdObj('w', 'Nc3'));

var_export($board->getMovetext());

Output:

'1.e4 d5 2.exd5 Qxd5 3.Nc3'