Auxuliary Class
Auxuliary methods This is not actually a class, but a necessary convention to get YUIdoc to document standalone items.
Item Index
Methods
- clean
- confirmMove
- finishMove
- getBishopCoveredFields
- getBishopCoveredFieldsHelper
- getBishopDirections
- getBishopFieldBehind
- getBishopFieldBehindHelper
- getBishopLegalMoves
- getBishopLegalMovesHelper
- getCanvasCoordinates
- getChessCoordinates
- getHTMLcharFromNotation
- getMousePos
- getMoveSummary
- getNotationCoordinates
- getPawnCaptureNotation
- getRookCoveredFields
- getRookCoveredFieldsHelper
- getRookDirections
- getRookFieldBehind
- getRookFieldBehindHelper
- getRookLegalMoves
- getRookLegalMovesHelper
- getXNotationCoordinate
- getXYfromNotationCoordinates
- getYNotationCoordinate
- isKingAttacked
- isNormalInteger
- isStalemate
- isStalemate
- preventCheck
- removeCapturedPiece
- roundRect
- unixTimeStampToTimerString
Methods
clean
-
deleteValue
removes an elements from an array with a given value credit: http://stackoverflow.com/questions/281264/remove-empty-elements-from-an-array-in-javascript/281335#281335
Parameters:
-
deleteValue
Objecta values to delete
Returns:
cleaned array
confirmMove
-
piece
-
x
-
y
checks whatever the move is a legal move for a given piece
Parameters:
-
piece
Objecta piece to check the validity of the move
-
x
NumberX coordinate of the destination field on the chess board
-
y
NumberY coordinate of the destination field on the chess board
Returns:
true if the move is a legal move for a given piece, false otherwise
finishMove
-
piece
-
x
-
y
generates move summary of the move for a given piece
Parameters:
-
piece
Objecta piece to move
-
x
NumberX coordinate of the destination field on the chess board
-
y
NumberY coordinate of the destination field on the chess board
Returns:
an object represents a summary of the move
getBishopCoveredFields
-
x
-
y
-
color
calculates an array of covered fields for a piece in a diagonal directions
Parameters:
-
x
NumberX coordinate of the field on the chess board
-
y
NumberY coordinate of the field on the chess board
-
color
Stringcolor of the piece, valid values are 'black' and 'white'
Returns:
an array of covered fields
getBishopCoveredFieldsHelper
-
x
-
y
-
color
-
direction
calculates an array of fields covered by a piece in diagonal directions given an initial coordinates of the piece and direction. Helper method.
Parameters:
-
x
NumberX coordinate of the field on the chess board
-
y
NumberY coordinate of the field on the chess board
-
color
Stringcolor of the atacking piece, valid values are 'black' and 'white'
-
direction
Stringdirection to increment. Valid values are 'right', 'left', 'down' and 'up'
Returns:
an array of fields covered by a piece
getBishopDirections
-
x
-
y
-
direction
Increments chess coordinates to a given diagonal direction. Helper method.
Parameters:
-
x
NumberX coordinate of the field on the chess board
-
y
NumberY coordinate of the field on the chess board
-
direction
Stringdirection to increment. Valid values are 'up-right', 'up-left', 'down-right' and 'down-left'
Returns:
incremented chess coordinates
getBishopFieldBehind
-
x
-
y
-
color
calculates coordinate of the field behind the opponent King in a diagonal directions given an initial coordinates of the atacking piece
Parameters:
-
x
NumberX coordinate of the field on the chess board
-
y
NumberY coordinate of the field on the chess board
-
color
Stringcolor of the atacking piece, valid values are 'black' and 'white'
Returns:
a coordinate of the field behind the opponent's king
getBishopFieldBehindHelper
-
x
-
y
-
color
-
direction
calculates coordinate of the field behind the opponent King in a diagonal directions given an initial coordinates of the atacking piece and direction. Necessary for calculation of the King's legal moves. Helper method.
Parameters:
-
x
NumberX coordinate of the field on the chess board
-
y
NumberY coordinate of the field on the chess board
-
color
Stringcolor of the atacking piece, valid values are 'black' and 'white'
-
direction
Stringdirection to increment. Valid values are 'up-right', 'up-left', 'down-right' and 'down-left'
Returns:
a coordinate of the field behind the opponent's king
getBishopLegalMoves
-
x
-
y
-
color
calculates an array of legal moves for a piece in a diagonal directions
Parameters:
-
x
NumberX coordinate of the field on the chess board
-
y
NumberY coordinate of the field on the chess board
-
color
Stringcolor of the piece, valid values are 'black' and 'white'
Returns:
an array of legal moves
getBishopLegalMovesHelper
-
x
-
y
-
color
-
direction
calculates moves in a diagonal directions given an initial coordinates and a direction. Helper method.
Parameters:
-
x
NumberX coordinate of the field on the chess board
-
y
NumberY coordinate of the field on the chess board
-
color
Stringcolor of the piece, valid values are 'black' and 'white'
-
direction
Stringdirection to increment. Valid values are 'up-right', 'up-left', 'down-right' and 'down-left'
Returns:
an array of moves
getCanvasCoordinates
-
x
-
y
-
fieldsize
converts coordinates of the chess board to a coordinates of the canvas plane
Parameters:
-
x
Numberx coordinate on the canvas plane
-
y
Numbery coordinate on the canvas plane
-
fieldsize
Numbersize of the chess field
Returns:
coordinates on the canvas plane
getChessCoordinates
-
evt
converts mouse coordinates to a coordinates on the chess board invarian of the side perspective
Parameters:
-
evt
Objectmouse event
Returns:
player invariant coordinates on chess board
getHTMLcharFromNotation
-
str
-
color
converts piece notation symbol to a HTML Entitiy, representing a piece
Parameters:
-
str
Stringpiece notation symbol
-
color
Stringcolor of the piece, valid values are 'black' and 'white'
Returns:
HTML Entity
getMousePos
-
c
-
evt
converts mouse coordinates to a coordinates on the chess board
Parameters:
-
c
Objectcanvas context
-
evt
Objectmouse event
Returns:
coordinates on chess board
getMoveSummary
-
piece
-
alternativePieces
-
origin
-
destination
-
castling
-
isCapture
-
isCheck
-
isMate
-
isStalemate
-
promotion
-
enpassant
generates move summary of a given input data that King can not be atacked by opponent piece
Parameters:
-
piece
Objecta piece, which move is summarised
-
alternativePieces
Objectan array of pieces if the same type, which can reach the same destination field
-
origin
Objectcoordinates of origin
-
destination
Objectcoordinates of destination
-
castling
Stringa string represents a castling, valid values are 'short' for king side castling, 'long' for queen side castling or empty string if the move was not a castling
-
isCapture
Booleana boolean flag indicating if the move was a capture
-
isCheck
Booleana boolean flag indicating if the move was a check against an opponent king
-
isMate
Booleana boolean flag indicating if the move was a checkmate against the opponent
-
isStalemate
Booleana boolean flag indicating if the move achieved a stalemate
-
promotion
Stringa string indicating that the move was a promotion of a pawn. Valid values are 'Q' for Queen, 'R' for the Rook, 'N' for the Knight, 'B' for the Bishop or 'none' if the move was not a promotion
-
enpassant
Stringnotation coordinates of the pawn indicating that the pawn can be taken en passant
Returns:
an object represents a summary of the move
getNotationCoordinates
-
coor
converts chess coordinate to a notation coordinates string for a given field
Parameters:
-
coor
Objectcoordinate of the field
Returns:
notation coordinates string
getPawnCaptureNotation
-
origin
-
destination
generates pawn capture notation string for a given move
Parameters:
-
origin
Objectcoordinate of origin field on the chess board
-
destination
Objectcoordinate of the destination field on the chess board
Returns:
pawn capture notation string
getRookCoveredFields
-
x
-
y
-
color
calculates an array of covered fields for a piece in a lateral directions
Parameters:
-
x
NumberX coordinate of the field on the chess board
-
y
NumberY coordinate of the field on the chess board
-
color
Stringcolor of the piece, valid values are 'black' and 'white'
Returns:
an array of covered fields
getRookCoveredFieldsHelper
-
x
-
y
-
color
-
direction
calculates an array of fields covered by a piece in lateral directions given an initial coordinates of the piece and direction. Helper method.
Parameters:
-
x
NumberX coordinate of the field on the chess board
-
y
NumberY coordinate of the field on the chess board
-
color
Stringcolor of the atacking piece, valid values are 'black' and 'white'
-
direction
Stringdirection to increment. Valid values are 'right', 'left', 'down' and 'up'
Returns:
an array of fields covered by a piece
getRookDirections
-
x
-
y
-
direction
Increments chess coordinates to a given lateral direction. Helper method.
Parameters:
-
x
NumberX coordinate of the field on the chess board
-
y
NumberY coordinate of the field on the chess board
-
direction
Stringdirection to increment. Valid values are 'right', 'left', 'down' and 'up'
Returns:
incremented chess coordinates
getRookFieldBehind
-
x
-
y
-
color
calculates coordinate of the field behind the opponent King in a lateral directions given an initial coordinates of the atacking piece
Parameters:
-
x
NumberX coordinate of the field on the chess board
-
y
NumberY coordinate of the field on the chess board
-
color
Stringcolor of the atacking piece, valid values are 'black' and 'white'
Returns:
a coordinate of the field behind the opponent's king
getRookFieldBehindHelper
-
x
-
y
-
color
-
direction
calculates coordinate of the field behind the opponent King in a lateral directions given an initial coordinates of the atacking piece and direction. Necessary for calculation of the King's legal moves. Helper method.
Parameters:
-
x
NumberX coordinate of the field on the chess board
-
y
NumberY coordinate of the field on the chess board
-
color
Stringcolor of the atacking piece, valid values are 'black' and 'white'
-
direction
Stringdirection to increment. Valid values are 'right', 'left', 'down' and 'up'
Returns:
a coordinate of the field behind the opponent's king
getRookLegalMoves
-
x
-
y
-
color
calculates an array of legal moves for a piece in a lateral directions
Parameters:
-
x
NumberX coordinate of the field on the chess board
-
y
NumberY coordinate of the field on the chess board
-
color
Stringcolor of the piece, valid values are 'black' and 'white'
Returns:
an array of legal moves
getRookLegalMovesHelper
-
x
-
y
-
color
-
direction
calculates moves in a lateral directions given an initial coordinates and a direction. Helper method.
Parameters:
-
x
NumberX coordinate of the field on the chess board
-
y
NumberY coordinate of the field on the chess board
-
color
Stringcolor of the piece, valid values are 'black' and 'white'
-
direction
Stringdirection to increment. Valid values are 'right', 'left', 'down' and 'up'
Returns:
an array of moves
getXNotationCoordinate
-
x
converts X coordinate of the chess board field to a notation-friendly rank coordinate
Parameters:
-
x
NumberX coordinate
Returns:
notation-friendly rank coordinate
getXYfromNotationCoordinates
-
notation
converts notation coordinates to the chess board coordinates
Parameters:
-
notation
Stringcoordinates
Returns:
chess board coordinates
getYNotationCoordinate
-
y
converts Y coordinate of the chess board field to a notation-friendly file coordinate
Parameters:
-
y
NumberY coordinate
Returns:
notation-friendly file coordinate
isKingAttacked
-
color
check whatever is King under atack
Parameters:
-
color
Stringcolor of the King
Returns:
true if King is under atack, false otherwise
isNormalInteger
-
str
checks if string represents a valud positive integer credit: http://stackoverflow.com/questions/10834796/validate-that-a-string-is-a-positive-integer/10834843#10834843
Parameters:
-
str
Stringstring to be checked
Returns:
true if an input is a positive integer, false otherwise
isStalemate
-
color
check whatever the position is checkmate for a given side
Parameters:
-
color
Stringcolor of the side, valid values are 'black' and 'white'
Returns:
true if position is checkmate, false otherwise
isStalemate
-
color
check whatever the position is stalemate for a given side
Parameters:
-
color
Stringcolor of the side, valid values are 'black' and 'white'
Returns:
true if position is stalemate, false otherwise
preventCheck
-
piece
-
legalMoves
filters an array of legal moves for a given piece, restricting the movement of a piece in a such a way that King can not be atacked by opponent piece
Parameters:
-
piece
Objectpiece, movement of which to be restricted
-
legalMoves
Arrayan array of legal moves of the piece
Returns:
filtered array of a legal moves
removeCapturedPiece
-
x
-
y
removes captured piece from a pieces array of the board object
Parameters:
-
x
NumberX coordinate of the captured piece on the chess board
-
y
NumberY coordinate of the captured piece on the chess board
Returns:
true if piece is found, false otherwise
roundRect
-
ctx
-
x
-
y
-
width
-
height
-
radius
-
fill
-
stroke
draws rounded rectangle on the canvas plane credit: http://stackoverflow.com/questions/1255512/how-to-draw-a-rounded-rectangle-on-html-canvas/7592676#7592676
Parameters:
-
ctx
Numbercanvas context
-
x
Numberx coordinate on the canvas plane
-
y
Numbery coordinate on the canvas plane
-
width
Numberwidth of the rectangle
-
height
Numberheight of the rectangle
-
radius
Numbercorner radius
-
fill
Booleanfill boolean flag
-
stroke
Booleanstroke boolean flag
unixTimeStampToTimerString
-
ts
converts unix timestamp to a human readable string in mm:ss format
Parameters:
-
ts
Numberunix timestamp
Returns:
time in mm:ss format