Board
in package
Table of Contents
Constants
Properties
- $board : array<int, array<int, ChessPiece|null>>
- $canCastle : array<string|int, mixed>
- $enPassantPawn : Loc|null
- $numMoves : int
Methods
- __construct() : mixed
- canCastle() : bool
- clear() : void
- Remove all pieces from the board
- clearSquare() : void
- Remove the piece, if any, from this square
- deepCopy() : self
- getBoardDisplay() : array<int, array<int, ChessPiece|null>>
- Get the board from the colour's perspective as an array.
- getCurrentTurnColour() : Colour
- getEnPassantPawn() : Loc|null
- getFEN() : string
- getKing() : ChessPiece
- getPiece() : ChessPiece
- getPieceOrNull() : ChessPiece|null
- getPieces() : array<string|int, ChessPiece>
- hasPiece() : bool
- isChecked() : bool
- Is the $colour King being attacked by any enemy pieces?
- isCheckmated() : bool
- isDraw() : bool
- movePiece() : ChessPiece, EnPassant: bool, PawnPromotion: bool}
- Move a piece. Note that legality of the move is not checked here.
- setCastling() : void
- setEnPassantPawn() : void
- setSquare() : void
- Change the position of a piece on the board
- hasLegalMoves() : bool
- Can $colour make any legal moves in the current position?
- 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
$enPassantPawn
private
Loc|null
$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
boolclear()
Remove all pieces from the board
public
clear() : void
clearSquare()
Remove the piece, if any, from this square
public
clearSquare(Loc $loc) : void
Parameters
- $loc : Loc
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() : Loc|null
Return values
Loc|nullgetFEN()
public
getFEN() : string
Return values
stringgetKing()
public
getKing(Colour $colour) : ChessPiece
Parameters
- $colour : Colour
Return values
ChessPiecegetPiece()
public
getPiece(Loc $loc) : ChessPiece
Parameters
- $loc : Loc
Return values
ChessPiecegetPieceOrNull()
public
getPieceOrNull(Loc $loc) : ChessPiece|null
Parameters
- $loc : Loc
Return values
ChessPiece|nullgetPieces()
public
getPieces([Colour|null $colour = null ]) : array<string|int, ChessPiece>
Parameters
- $colour : Colour|null = null
Return values
array<string|int, ChessPiece>hasPiece()
public
hasPiece(Loc $loc) : bool
Parameters
- $loc : Loc
Return values
boolisChecked()
Is the $colour King being attacked by any enemy pieces?
public
isChecked(Colour $colour) : bool
Parameters
- $colour : Colour
Return values
boolisCheckmated()
public
isCheckmated(Colour $colour) : bool
Parameters
- $colour : Colour
Return values
boolisDraw()
public
isDraw(Colour $colour) : bool
Parameters
- $colour : Colour
Return values
boolmovePiece()
Move a piece. Note that legality of the move is not checked here.
public
movePiece(Loc $loc, Loc $toLoc[, int $pawnPromotionPiece = ChessPiece::QUEEN ]) : ChessPiece, EnPassant: bool, PawnPromotion: bool}
Parameters
- $loc : Loc
- $toLoc : Loc
- $pawnPromotionPiece : int = ChessPiece::QUEEN
Return values
ChessPiece, EnPassant: bool, PawnPromotion: bool}setCastling()
public
setCastling(Colour $colour, array<string|int, Castling> $castling) : void
Parameters
setEnPassantPawn()
public
setEnPassantPawn(Loc|null $enPassantPawn) : void
Parameters
- $enPassantPawn : Loc|null
setSquare()
Change the position of a piece on the board
public
setSquare(Loc $loc, ChessPiece $piece) : void
Parameters
- $loc : Loc
- $piece : ChessPiece
hasLegalMoves()
Can $colour make any legal moves in the current position?
private
hasLegalMoves(Colour $colour) : bool
Parameters
- $colour : Colour
Return values
boolinitialize()
private
initialize() : void