Constructor
new Piece(args)
Create a piece.
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
args |
Object | The properties of a piece.
Properties
|
Members
asJson
The piece serialized as a simple object.
constructorName :string
Type:
- string
dup
Make a duplicate of the piece.
hasMoved :boolean
Type:
- boolean
id :number
Type:
- number
opponent
The opponent of the piece's owner.
playerNumber :number
Type:
- number
selected :boolean
Type:
- boolean
type :string
Type:
- string
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. |
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. |
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. |
Returns:
- Type
- SquareSet
deselect() → {boolean}
Unmark the piece as selected;
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. |
Returns:
- Type
- SquareSet
enPassantSquare() → {Square|null}
The en passant square.
Defaults to null.
Returns:
- Type
- Square | null
select() → {boolean}
Mark the piece as selected;
Returns:
- Type
- boolean
switchPlayer() → {boolean}
Change the owner of the piece;
Returns:
- Type
- boolean