Board
in package
Table of Contents
Constants
Properties
- $board : array<int, array<int, ChessPiece|null>>
- $canCastle : array<string|int, mixed>
- $enPassantPawn : array{X: int, Y: int}
- $numMoves : int
Methods
- __construct() : mixed
- canCastle() : bool
- clearSquare() : void
- deepCopy() : self
- getBoardDisplay() : array<int, array<int, ChessPiece|null>>
- Get the board from the colour's perspective as an array.
- getCurrentTurnColour() : Colour
- getEnPassantPawn() : array{X: int, Y: int}
- getFEN() : string
- getKing() : ChessPiece
- getPiece() : ChessPiece
- getPieces() : array<string|int, ChessPiece>
- hasPiece() : bool
- isChecked() : bool
- Is the $colour King being attacked by any enemy pieces?
- isValidCoord() : bool
- movePiece() : ChessPiece, EnPassant: bool, PawnPromotion: bool}
- Move a piece. Note that legality of the move is not checked here.
- setSquare() : void
- Change the position of a piece on the board
- initialize() : void
Constants
NX
public
mixed
NX
= 8
NY
public
mixed
NY
= 8
Properties
$board
private
array<int, array<int, ChessPiece|null>>
$board
$canCastle
private
array<string|int, mixed>
$canCastle
array<value-of<Colour>, array<Castling>>
$enPassantPawn
private
array{X: int, Y: int}
$enPassantPawn
$numMoves
private
int
$numMoves
= 0
Methods
__construct()
public
__construct([bool $initialize = true ]) : mixed
Parameters
- $initialize : bool = true
canCastle()
public
canCastle(Colour $colour, Castling $type) : bool
Parameters
Return values
boolclearSquare()
public
clearSquare(int $x, int $y) : void
Parameters
- $x : int
- $y : int
deepCopy()
public
deepCopy() : self
Return values
selfgetBoardDisplay()
Get the board from the colour's perspective as an array.
public
getBoardDisplay(bool $playerIsWhite) : array<int, array<int, ChessPiece|null>>
The first dimension is the y-coordinate, second is x-coordinate.
Parameters
- $playerIsWhite : bool
Return values
array<int, array<int, ChessPiece|null>>getCurrentTurnColour()
public
getCurrentTurnColour() : Colour
Return values
ColourgetEnPassantPawn()
public
getEnPassantPawn() : array{X: int, Y: int}
Return values
array{X: int, Y: int}getFEN()
public
getFEN() : string
Return values
stringgetKing()
public
getKing(Colour $colour) : ChessPiece
Parameters
- $colour : Colour
Return values
ChessPiecegetPiece()
public
getPiece(int $x, int $y) : ChessPiece
Parameters
- $x : int
- $y : int
Return values
ChessPiecegetPieces()
public
getPieces([Colour|null $colour = null ]) : array<string|int, ChessPiece>
Parameters
- $colour : Colour|null = null
Return values
array<string|int, ChessPiece>hasPiece()
public
hasPiece(int $x, int $y) : bool
Parameters
- $x : int
- $y : int
Return values
boolisChecked()
Is the $colour King being attacked by any enemy pieces?
public
isChecked(Colour $colour) : bool
Parameters
- $colour : Colour
Return values
boolisValidCoord()
public
static isValidCoord(int $x, int $y) : bool
Parameters
- $x : int
- $y : int
Return values
boolmovePiece()
Move a piece. Note that legality of the move is not checked here.
public
movePiece(int $x, int $y, int $toX, int $toY[, int $pawnPromotionPiece = ChessPiece::QUEEN ]) : ChessPiece, EnPassant: bool, PawnPromotion: bool}
Parameters
- $x : int
- $y : int
- $toX : int
- $toY : int
- $pawnPromotionPiece : int = ChessPiece::QUEEN
Return values
ChessPiece, EnPassant: bool, PawnPromotion: bool}setSquare()
Change the position of a piece on the board
public
setSquare(int $x, int $y, ChessPiece $piece) : void
Parameters
- $x : int
- $y : int
- $piece : ChessPiece
initialize()
private
initialize() : void