Methods
addPiece(boardPiece, piecePosition)
Add a piece to the position
This:
- {Board}
Parameters:
Name | Type | Description |
---|---|---|
boardPiece |
BoardPiece | piece to add. |
piecePosition |
PiecePosition | where to add the piece. |
addPiecePostAddCallback(f)
Add a callback for adding a piece
This:
- {Board}
Parameters:
Name | Type | Description |
---|---|---|
f |
function | callback function. |
addPiecePostMoveCallback(f)
Add a callback for moving a piece
This:
- {Board}
Parameters:
Name | Type | Description |
---|---|---|
f |
function | callback function. |
addPiecePostRemoveCallback(f)
Add a callback for removing a piece
This:
- {Board}
Parameters:
Name | Type | Description |
---|---|---|
f |
function | callback function. |
addPieceVals(color, type, x, y)
Add a piece to the position (seperate pieces of data).
This:
- {Board}
Parameters:
Name | Type | Description |
---|---|---|
color |
string | color of the piece (black/white). |
type |
string | type of the piece (rook/knight/bishop/queen/king/pawn). |
x |
number | x location of the piece [0..8). |
y |
number | y location of the piece [0..8). |
checkBoardPieceAt(boardPiece, piecePosition)
Check that a certain piece is at a certain position.
Will throw an exception if that is not the case.
This:
- {Board}
Parameters:
Name | Type | Description |
---|---|---|
boardPiece |
BoardPiece | the piece in question. |
piecePosition |
PiecePosition | position to check that a piece is at. |
checkNoPieceAt(piecePosition)
Check that no piece is at a certain position.
Will throw an exception if that is not the case.
This:
- {Board}
Parameters:
Name | Type | Description |
---|---|---|
piecePosition |
PiecePosition | position to check that no piece is at. |
checkPieceAt(piecePosition)
Check that piece is at a certain position.
Will throw an exception if that is not the case.
This:
- {Board}
Parameters:
Name | Type | Description |
---|---|---|
piecePosition |
PiecePosition | position to check that a piece is at. |
clearPieces()
Clear the board
This:
- {Board}
forEachPiece(f)
Run a function for each piece in this position
This:
- {Board}
Parameters:
Name | Type | Description |
---|---|---|
f |
function | function to be called back for each piece. This function should receive the piece to work on. |
getPieceAtPosition(piecePosition) → {BoardPiece}
Get a piece at a specific position
This:
- {Board}
Parameters:
Name | Type | Description |
---|---|---|
piecePosition |
PiecePosition | position to get the piece at. |
Returns:
the piece at the specified position.
- Type
- BoardPiece
getPieceAtPositionVals(x, y) → {BoardPiece}
Get a piece at a specific position (in parts)
This:
- {Board}
Parameters:
Name | Type | Description |
---|---|---|
x |
number | x position to get piece at [0..8). |
y |
number | y position to get piece at [0..8). |
Returns:
the piece at the specified position.
- Type
- BoardPiece
getPiecePosition(boardPiece) → {PiecePosition}
Get the position of a piece
This:
- {Board}
Parameters:
Name | Type | Description |
---|---|---|
boardPiece |
BoardPiece | piece to get the position for. |
Returns:
the position of the piece in question.
- Type
- PiecePosition
hasPieceAtPosition(piecePosition) → {boolean}
Do we have a piece in a specific position?
This:
- {Board}
Parameters:
Name | Type | Description |
---|---|---|
piecePosition |
PiecePosition | position to check for a piece at. |
Returns:
whether there is a piece at the position.
- Type
- boolean
hasPieceAtPositionVals(x, y) → {boolean}
Do we have a piece in a specific position?
This:
- {Board}
Parameters:
Name | Type | Description |
---|---|---|
x |
number | x position to check for piece at [0..8). |
y |
number | y position to check for piece at [0..8). |
Returns:
is there a piece at position.
- Type
- boolean
initialize() → {Board}
creates a new instance
This:
- {Board}
Returns:
the new object created.
- Type
- Board
movePiece(boardPiece, fromPiecePosition, toPiecePosition)
Move a piece
This:
- {Board}
Parameters:
Name | Type | Description |
---|---|---|
boardPiece |
BoardPiece | piece to move. |
fromPiecePosition |
PiecePosition | from where to move the piece. |
toPiecePosition |
PiecePosition | to where to move the piece. |
movePieceByPos(fromPiecePosition, toPiecePosition)
Move a piece according to positions.
This:
- {Board}
Parameters:
Name | Type | Description |
---|---|---|
fromPiecePosition |
PiecePosition | from where to move. |
toPiecePosition |
PiecePosition | to where to move. |
removePiece(boardPiece, piecePosition)
Remove a piece
This:
- {Board}
Parameters:
Name | Type | Description |
---|---|---|
boardPiece |
BoardPiece | piece to remove. |
piecePosition |
PiecePosition | the position to remove it from. |
setPosition(boardPosition)
Clear the board and add a position to the current board
This:
- {Board}
Parameters:
Name | Type | Description |
---|---|---|
boardPosition |
BoardPosition | position to set. |
startPosition()
Put the board in starting position of standard chess.
This:
- {Board}
toString() → {string}
toString method that allows you to get a nice printout for this type
This:
- {Board}
Returns:
string representation of this object.
- Type
- string