API Docs for:
Show:

Auxuliary Class

Defined in: js/auxiliary.js:6
Module: Auxuliary

Auxuliary methods This is not actually a class, but a necessary convention to get YUIdoc to document standalone items.

Methods

clean

(
  • deleteValue
)
Array

Defined in js/auxiliary.js:83

Parameters:

  • deleteValue Object

    a values to delete

Returns:

Array:

cleaned array

confirmMove

(
  • piece
  • x
  • y
)
Boolean

Defined in js/auxiliary.js:849

checks whatever the move is a legal move for a given piece

Parameters:

  • piece Object

    a piece to check the validity of the move

  • x Number

    X coordinate of the destination field on the chess board

  • y Number

    Y coordinate of the destination field on the chess board

Returns:

Boolean:

true if the move is a legal move for a given piece, false otherwise

finishMove

(
  • piece
  • x
  • y
)
Object

Defined in js/auxiliary.js:870

generates move summary of the move for a given piece

Parameters:

  • piece Object

    a piece to move

  • x Number

    X coordinate of the destination field on the chess board

  • y Number

    Y coordinate of the destination field on the chess board

Returns:

Object:

an object represents a summary of the move

getBishopCoveredFields

(
  • x
  • y
  • color
)
Array

Defined in js/auxiliary.js:525

calculates an array of covered fields for a piece in a diagonal directions

Parameters:

  • x Number

    X coordinate of the field on the chess board

  • y Number

    Y coordinate of the field on the chess board

  • color String

    color of the piece, valid values are 'black' and 'white'

Returns:

Array:

an array of covered fields

getBishopCoveredFieldsHelper

(
  • x
  • y
  • color
  • direction
)
Array

Defined in js/auxiliary.js:430

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 Number

    X coordinate of the field on the chess board

  • y Number

    Y coordinate of the field on the chess board

  • color String

    color of the atacking piece, valid values are 'black' and 'white'

  • direction String

    direction to increment. Valid values are 'right', 'left', 'down' and 'up'

Returns:

Array:

an array of fields covered by a piece

getBishopDirections

(
  • x
  • y
  • direction
)
Object

Defined in js/auxiliary.js:199

Increments chess coordinates to a given diagonal direction. Helper method.

Parameters:

  • x Number

    X coordinate of the field on the chess board

  • y Number

    Y coordinate of the field on the chess board

  • direction String

    direction to increment. Valid values are 'up-right', 'up-left', 'down-right' and 'down-left'

Returns:

Object:

incremented chess coordinates

getBishopFieldBehind

(
  • x
  • y
  • color
)
Object

Defined in js/auxiliary.js:586

calculates coordinate of the field behind the opponent King in a diagonal directions given an initial coordinates of the atacking piece

Parameters:

  • x Number

    X coordinate of the field on the chess board

  • y Number

    Y coordinate of the field on the chess board

  • color String

    color of the atacking piece, valid values are 'black' and 'white'

Returns:

Object:

a coordinate of the field behind the opponent's king

getBishopFieldBehindHelper

(
  • x
  • y
  • color
  • direction
)
Object

Defined in js/auxiliary.js:333

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 Number

    X coordinate of the field on the chess board

  • y Number

    Y coordinate of the field on the chess board

  • color String

    color of the atacking piece, valid values are 'black' and 'white'

  • direction String

    direction to increment. Valid values are 'up-right', 'up-left', 'down-right' and 'down-left'

Returns:

Object:

a coordinate of the field behind the opponent's king

getBishopLegalMoves

(
  • x
  • y
  • color
)
Array

Defined in js/auxiliary.js:505

calculates an array of legal moves for a piece in a diagonal directions

Parameters:

  • x Number

    X coordinate of the field on the chess board

  • y Number

    Y coordinate of the field on the chess board

  • color String

    color of the piece, valid values are 'black' and 'white'

Returns:

Array:

an array of legal moves

getBishopLegalMovesHelper

(
  • x
  • y
  • color
  • direction
)
Array

Defined in js/auxiliary.js:253

calculates moves in a diagonal directions given an initial coordinates and a direction. Helper method.

Parameters:

  • x Number

    X coordinate of the field on the chess board

  • y Number

    Y coordinate of the field on the chess board

  • color String

    color of the piece, valid values are 'black' and 'white'

  • direction String

    direction to increment. Valid values are 'up-right', 'up-left', 'down-right' and 'down-left'

Returns:

Array:

an array of moves

getCanvasCoordinates

(
  • x
  • y
  • fieldsize
)
Object

Defined in js/auxiliary.js:60

converts coordinates of the chess board to a coordinates of the canvas plane

Parameters:

  • x Number

    x coordinate on the canvas plane

  • y Number

    y coordinate on the canvas plane

  • fieldsize Number

    size of the chess field

Returns:

Object:

coordinates on the canvas plane

getChessCoordinates

(
  • evt
)
Object

Defined in js/auxiliary.js:117

converts mouse coordinates to a coordinates on the chess board invarian of the side perspective

Parameters:

  • evt Object

    mouse event

Returns:

Object:

player invariant coordinates on chess board

getHTMLcharFromNotation

(
  • str
  • color
)
String

Defined in js/auxiliary.js:153

converts piece notation symbol to a HTML Entitiy, representing a piece

Parameters:

  • str String

    piece notation symbol

  • color String

    color of the piece, valid values are 'black' and 'white'

Returns:

String:

HTML Entity

getMousePos

(
  • c
  • evt
)
Object

Defined in js/auxiliary.js:100

converts mouse coordinates to a coordinates on the chess board

Parameters:

  • c Object

    canvas context

  • evt Object

    mouse event

Returns:

Object:

coordinates on chess board

getMoveSummary

(
  • piece
  • alternativePieces
  • origin
  • destination
  • castling
  • isCapture
  • isCheck
  • isMate
  • isStalemate
  • promotion
  • enpassant
)
Object

Defined in js/auxiliary.js:754

generates move summary of a given input data that King can not be atacked by opponent piece

Parameters:

  • piece Object

    a piece, which move is summarised

  • alternativePieces Object

    an array of pieces if the same type, which can reach the same destination field

  • origin Object

    coordinates of origin

  • destination Object

    coordinates of destination

  • castling String

    a 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 Boolean

    a boolean flag indicating if the move was a capture

  • isCheck Boolean

    a boolean flag indicating if the move was a check against an opponent king

  • isMate Boolean

    a boolean flag indicating if the move was a checkmate against the opponent

  • isStalemate Boolean

    a boolean flag indicating if the move achieved a stalemate

  • promotion String

    a 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 String

    notation coordinates of the pawn indicating that the pawn can be taken en passant

Returns:

Object:

an object represents a summary of the move

getNotationCoordinates

(
  • coor
)
String

Defined in js/auxiliary.js:944

converts chess coordinate to a notation coordinates string for a given field

Parameters:

  • coor Object

    coordinate of the field

Returns:

String:

notation coordinates string

getPawnCaptureNotation

(
  • origin
  • destination
)
String

Defined in js/auxiliary.js:954

generates pawn capture notation string for a given move

Parameters:

  • origin Object

    coordinate of origin field on the chess board

  • destination Object

    coordinate of the destination field on the chess board

Returns:

String:

pawn capture notation string

getRookCoveredFields

(
  • x
  • y
  • color
)
Array

Defined in js/auxiliary.js:566

calculates an array of covered fields for a piece in a lateral directions

Parameters:

  • x Number

    X coordinate of the field on the chess board

  • y Number

    Y coordinate of the field on the chess board

  • color String

    color of the piece, valid values are 'black' and 'white'

Returns:

Array:

an array of covered fields

getRookCoveredFieldsHelper

(
  • x
  • y
  • color
  • direction
)
Array

Defined in js/auxiliary.js:467

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 Number

    X coordinate of the field on the chess board

  • y Number

    Y coordinate of the field on the chess board

  • color String

    color of the atacking piece, valid values are 'black' and 'white'

  • direction String

    direction to increment. Valid values are 'right', 'left', 'down' and 'up'

Returns:

Array:

an array of fields covered by a piece

getRookDirections

(
  • x
  • y
  • direction
)
Object

Defined in js/auxiliary.js:226

Increments chess coordinates to a given lateral direction. Helper method.

Parameters:

  • x Number

    X coordinate of the field on the chess board

  • y Number

    Y coordinate of the field on the chess board

  • direction String

    direction to increment. Valid values are 'right', 'left', 'down' and 'up'

Returns:

Object:

incremented chess coordinates

getRookFieldBehind

(
  • x
  • y
  • color
)
Object

Defined in js/auxiliary.js:614

calculates coordinate of the field behind the opponent King in a lateral directions given an initial coordinates of the atacking piece

Parameters:

  • x Number

    X coordinate of the field on the chess board

  • y Number

    Y coordinate of the field on the chess board

  • color String

    color of the atacking piece, valid values are 'black' and 'white'

Returns:

Object:

a coordinate of the field behind the opponent's king

getRookFieldBehindHelper

(
  • x
  • y
  • color
  • direction
)
Object

Defined in js/auxiliary.js:381

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 Number

    X coordinate of the field on the chess board

  • y Number

    Y coordinate of the field on the chess board

  • color String

    color of the atacking piece, valid values are 'black' and 'white'

  • direction String

    direction to increment. Valid values are 'right', 'left', 'down' and 'up'

Returns:

Object:

a coordinate of the field behind the opponent's king

getRookLegalMoves

(
  • x
  • y
  • color
)
Array

Defined in js/auxiliary.js:546

calculates an array of legal moves for a piece in a lateral directions

Parameters:

  • x Number

    X coordinate of the field on the chess board

  • y Number

    Y coordinate of the field on the chess board

  • color String

    color of the piece, valid values are 'black' and 'white'

Returns:

Array:

an array of legal moves

getRookLegalMovesHelper

(
  • x
  • y
  • color
  • direction
)
Array

Defined in js/auxiliary.js:293

calculates moves in a lateral directions given an initial coordinates and a direction. Helper method.

Parameters:

  • x Number

    X coordinate of the field on the chess board

  • y Number

    Y coordinate of the field on the chess board

  • color String

    color of the piece, valid values are 'black' and 'white'

  • direction String

    direction to increment. Valid values are 'right', 'left', 'down' and 'up'

Returns:

Array:

an array of moves

getXNotationCoordinate

(
  • x
)
String

Defined in js/auxiliary.js:999

converts X coordinate of the chess board field to a notation-friendly rank coordinate

Parameters:

  • x Number

    X coordinate

Returns:

String:

notation-friendly rank coordinate

getXYfromNotationCoordinates

(
  • notation
)
Object

Defined in js/auxiliary.js:965

converts notation coordinates to the chess board coordinates

Parameters:

  • notation String

    coordinates

Returns:

Object:

chess board coordinates

getYNotationCoordinate

(
  • y
)
String

converts Y coordinate of the chess board field to a notation-friendly file coordinate

Parameters:

  • y Number

    Y coordinate

Returns:

String:

notation-friendly file coordinate

isKingAttacked

(
  • color
)
Boolean

Defined in js/auxiliary.js:667

check whatever is King under atack

Parameters:

  • color String

    color of the King

Returns:

Boolean:

true if King is under atack, false otherwise

isNormalInteger

(
  • str
)
Boolean

Defined in js/auxiliary.js:142

Parameters:

  • str String

    string to be checked

Returns:

Boolean:

true if an input is a positive integer, false otherwise

isStalemate

(
  • color
)
Boolean

check whatever the position is checkmate for a given side

Parameters:

  • color String

    color of the side, valid values are 'black' and 'white'

Returns:

Boolean:

true if position is checkmate, false otherwise

isStalemate

(
  • color
)
Boolean

check whatever the position is stalemate for a given side

Parameters:

  • color String

    color of the side, valid values are 'black' and 'white'

Returns:

Boolean:

true if position is stalemate, false otherwise

preventCheck

(
  • piece
  • legalMoves
)
Array

Defined in js/auxiliary.js:691

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 Object

    piece, movement of which to be restricted

  • legalMoves Array

    an array of legal moves of the piece

Returns:

Array:

filtered array of a legal moves

removeCapturedPiece

(
  • x
  • y
)
Boolean

Defined in js/auxiliary.js:642

removes captured piece from a pieces array of the board object

Parameters:

  • x Number

    X coordinate of the captured piece on the chess board

  • y Number

    Y coordinate of the captured piece on the chess board

Returns:

Boolean:

true if piece is found, false otherwise

roundRect

(
  • ctx
  • x
  • y
  • width
  • height
  • radius
  • fill
  • stroke
)

Defined in js/auxiliary.js:12

Parameters:

  • ctx Number

    canvas context

  • x Number

    x coordinate on the canvas plane

  • y Number

    y coordinate on the canvas plane

  • width Number

    width of the rectangle

  • height Number

    height of the rectangle

  • radius Number

    corner radius

  • fill Boolean

    fill boolean flag

  • stroke Boolean

    stroke boolean flag

unixTimeStampToTimerString

(
  • ts
)
String

Defined in js/auxiliary.js:185

converts unix timestamp to a human readable string in mm:ss format

Parameters:

  • ts Number

    unix timestamp

Returns:

String:

time in mm:ss format