Class: State

State

new State()

State contains points and pieces and very basic methods to move pieces around without enforcing any rules. Those methods are responsible for required changes to internal state only, the UI layer should handle graphical movement of pieces itself.
Source:

Members

bar :Array.<Array>

Players have separate bar places and so separate list. First element of array is for white pieces and second one for black.
Type:
  • Array.<Array>
Source:

nextPieceID :number

Counter for generating unique IDs for pieces within this state
Type:
  • number
Source:

outside :Array.<Array>

Players have separate outside places and so separate list. First element of array is for white pieces and second one for black.
Type:
  • Array.<Array>
Source:

pieces

A two dimensional array is also used to store references to all white and black pieces independent of their position - just for convenience.
Source:

points :Array

All popular variants of the game have a total of 24 positions on the board and two positions outside - the place on the bar where pieces go when hit and the place next to board where pieces go when beared off. Number of positions is not strictly defined here to allow more options when creating new rules. The points, bar, outside and pieces properties should be initialized by the Rule object. Each element in those properties should contain a stack (last in, first out).
Type:
  • Array
Source:

Methods

(static) checkTopPieceType(state, position, type) → {boolean}

Get top piece, checking type in the process
Parameters:
Name Type Description
state State Board state
position number Denormalized point position
type PieceType Piece type
Source:
Returns:
- Returns true if top piece at position is of the specified type. Returns false if there are no pieces at that point.
Type
boolean

(static) clear(state)

Clear state
Parameters:
Name Type Description
state State Board state
Source:

(static) clone(state) → {State}

Creates a deep copy of state object
Parameters:
Name Type Description
state State Game state
Source:
Returns:
- New state object
Type
State

(static) countAllAtPos(state, position) → {number}

Count number of all pieces at selected position, regardless of type
Parameters:
Name Type Description
state State Board state
position number Denormalized point position
Source:
Returns:
- Number of pieces of specified type
Type
number

(static) countAtPos(state, position, type) → {number}

Count number of pieces of specified type at selected position
Parameters:
Name Type Description
state State Board state
position number Denormalized point position
type PieceType Piece type
Source:
Returns:
- Number of pieces of specified type
Type
number

(static) getBarTopPiece(state, type) → {Piece}

Get top piece at bar
Parameters:
Name Type Description
state State Board state
type PieceType Type of piece (white/black)
Source:
Returns:
- Returns type of top piece or null if there are no pieces at that position
Type
Piece

(static) getPiecePos(state, piece) → {number}

Get position of piece on board. Return null if the piece is on bar or outside the board.
Parameters:
Name Type Description
state State Game
piece Piece Piece
Source:
Returns:
- Position of piece on board or null if on bar/outside the board
Type
number

(static) getTopPiece(state, position) → {Piece}

Get top piece at specified position
Parameters:
Name Type Description
state State Board state
position number Denormalized point position
Source:
Returns:
- Returns type of top piece or null if there are no pieces at that position
Type
Piece

(static) getTopPieceType(state, position) → {PieceType}

Get type of top piece at specified position
Parameters:
Name Type Description
state State Board state
position number Denormalized point position
Source:
Returns:
- Returns type of top piece or null if there are no pieces at that position
Type
PieceType

(static) havePiecesOnBar(state, type) → {boolean}

Check if there are any pieces on the bar.
Parameters:
Name Type Description
state State State to check
type PieceType Type of piece (white/black)
Source:
Returns:
- True if there are any pieces on the bar
Type
boolean

(static) isPieceOnBar(state, piece) → {boolean}

Check if a specific piece is on the bar.
Parameters:
Name Type Description
state State State to check
piece Piece Piece
Source:
Returns:
- True if there are any pieces on the bar
Type
boolean

(static) isPieceOutside(state, piece) → {boolean}

Check if the piece is outside.
Parameters:
Name Type Description
state State State to check
piece Piece Piece
Source:
Returns:
- True if there are any pieces on the bar
Type
boolean

(static) isPosFree(state, position) → {boolean}

Check if there are no pieces at the specified point
Parameters:
Name Type Description
state State Board state
position number Denormalized point position
Source:
Returns:
- Returns true if there are no pieces at that point
Type
boolean