Class: Piece

Piece(args)

Abstract class representing a piece on the board.

Constructor

new Piece(args)

Create a piece.
Parameters:
Name Type Description
args Object The properties of a piece.
Properties
Name Type Attributes Default Description
player_number number The number of the player.
selected boolean <optional>
false Is the piece selected?
id string The unique identifier of the piece.
has_moved boolean <optional>
false Has the piece moved?
type string The type of the piece.
Source:

Members

asJson

The piece serialized as a simple object.
Source:

constructorName :string

Type:
  • string
Source:

dup

Make a duplicate of the piece.
Source:

hasMoved :boolean

Type:
  • boolean
Source:

id :number

Type:
  • number
Source:

opponent

The opponent of the piece's owner.
Source:

playerNumber :number

Type:
  • number
Source:

selected :boolean

Type:
  • boolean
Source:

type :string

Type:
  • string
Source:

Methods

canMove(from, to, game_state) → {boolean}

Can the piece move from the square to a specified square?
Parameters:
Name Type Description
from Square The square the piece is moving from.
to Square The square the piece is moving to.
game_state GameState The state of the game.
Source:
Returns:
Type
boolean

canMoveFrom(square, game_state) → {boolean}

Can the piece move from square?
Parameters:
Name Type Description
square Square The square the piece is moving from.
game_state GameState The state of the game.
Source:
Returns:
Type
boolean

captureSquares(square, game_state) → {SquareSet}

All the destinations the piece can move to that result in capture. Defaults to calling destinations function.
Parameters:
Name Type Description
square Square The square the piece is moving from.
game_state GameState The state of the game.
Source:
Returns:
Type
SquareSet

deselect() → {boolean}

Unmark the piece as selected;
Source:
Returns:
Type
boolean

destinations(square, game_state) → {SquareSet}

All the destinations the piece can move to. Abstract method implemented in each subclass.
Parameters:
Name Type Description
square Square The square the piece is moving from.
game_state GameState The state of the game.
Source:
Returns:
Type
SquareSet

enPassantSquare() → {Square|null}

The en passant square. Defaults to null.
Source:
Returns:
Type
Square | null

select() → {boolean}

Mark the piece as selected;
Source:
Returns:
Type
boolean

switchPlayer() → {boolean}

Change the owner of the piece;
Source:
Returns:
Type
boolean