Class: Board

Board

Represents a full board This is the main class to interact with. Using this class you can: 1. Use pieces: put, remove and move them. 2. Do something with all pieces.

Constructor

new Board()

Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

Methods

addPiece(boardPiece, piecePosition)

Add a piece to the position
This:
Parameters:
Name Type Description
boardPiece BoardPiece piece to add.
piecePosition PiecePosition where to add the piece.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

addPiecePostAddCallback(f)

Add a callback for adding a piece
This:
Parameters:
Name Type Description
f function callback function.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

addPiecePostMoveCallback(f)

Add a callback for moving a piece
This:
Parameters:
Name Type Description
f function callback function.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

addPiecePostRemoveCallback(f)

Add a callback for removing a piece
This:
Parameters:
Name Type Description
f function callback function.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

addPieceVals(color, type, x, y)

Add a piece to the position (seperate pieces of data).
This:
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).
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

checkBoardPieceAt(boardPiece, piecePosition)

Check that a certain piece is at a certain position. Will throw an exception if that is not the case.
This:
Parameters:
Name Type Description
boardPiece BoardPiece the piece in question.
piecePosition PiecePosition position to check that a piece is at.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

checkNoPieceAt(piecePosition)

Check that no piece is at a certain position. Will throw an exception if that is not the case.
This:
Parameters:
Name Type Description
piecePosition PiecePosition position to check that no piece is at.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

checkPieceAt(piecePosition)

Check that piece is at a certain position. Will throw an exception if that is not the case.
This:
Parameters:
Name Type Description
piecePosition PiecePosition position to check that a piece is at.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

clearPieces()

Clear the board
This:
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

forEachPiece(f)

Run a function for each piece in this position
This:
Parameters:
Name Type Description
f function function to be called back for each piece. This function should receive the piece to work on.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

getPieceAtPosition(piecePosition) → {BoardPiece}

Get a piece at a specific position
This:
Parameters:
Name Type Description
piecePosition PiecePosition position to get the piece at.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:
Returns:
the piece at the specified position.
Type
BoardPiece

getPieceAtPositionVals(x, y) → {BoardPiece}

Get a piece at a specific position (in parts)
This:
Parameters:
Name Type Description
x number x position to get piece at [0..8).
y number y position to get piece at [0..8).
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:
Returns:
the piece at the specified position.
Type
BoardPiece

getPiecePosition(boardPiece) → {PiecePosition}

Get the position of a piece
This:
Parameters:
Name Type Description
boardPiece BoardPiece piece to get the position for.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:
Returns:
the position of the piece in question.
Type
PiecePosition

hasPieceAtPosition(piecePosition) → {boolean}

Do we have a piece in a specific position?
This:
Parameters:
Name Type Description
piecePosition PiecePosition position to check for a piece at.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:
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:
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).
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:
Returns:
is there a piece at position.
Type
boolean

initialize() → {Board}

creates a new instance
This:
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:
Returns:
the new object created.
Type
Board

movePiece(boardPiece, fromPiecePosition, toPiecePosition)

Move a piece
This:
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.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

movePieceByPos(fromPiecePosition, toPiecePosition)

Move a piece according to positions.
This:
Parameters:
Name Type Description
fromPiecePosition PiecePosition from where to move.
toPiecePosition PiecePosition to where to move.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

removePiece(boardPiece, piecePosition)

Remove a piece
This:
Parameters:
Name Type Description
boardPiece BoardPiece piece to remove.
piecePosition PiecePosition the position to remove it from.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

setPosition(boardPosition)

Clear the board and add a position to the current board
This:
Parameters:
Name Type Description
boardPosition BoardPosition position to set.
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

startPosition()

Put the board in starting position of standard chess.
This:
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:

toString() → {string}

toString method that allows you to get a nice printout for this type
This:
Author:
  • mark.veltzer@gmail.com (Mark Veltzer)
Source:
Returns:
string representation of this object.
Type
string