Class: RuleBgTapa

RuleBgTapa

new RuleBgTapa()

Bulgarian variant of Tapa (тапа).
Source:

Extends

Members

country :string

Full name of country where this rule (variant) is played. To list multiple countries use a pipe ('|') character as separator.
Type:
  • string
Overrides:
Source:

countryCode :string

Two character ISO code of country where this rule (variant) is played. To list multiple codes use a pipe ('|') character as separator. List codes in same order as countries in the field above.
Type:
  • string
Overrides:
Source:

description :string

Full description of rule
Type:
  • string
Overrides:
Source:

maxPieces :number

The number of pieces each player has
Type:
  • number
Inherited From:
Source:

name :string

Rule name, matching the class name (eg. 'RuleBgTapa')
Type:
  • string
Overrides:
Source:

title :string

Short title describing rule specifics
Type:
  • string
Overrides:
Source:

Methods

allPiecesAreHome(state, type) → {boolean}

Check if all pieces are in the home field.
Parameters:
Name Type Description
state State State to change
type PieceType Type of piece (white/black)
Inherited From:
Source:
Returns:
- True if all pieces are in home field
Type
boolean

applyMoveActions(state, actionList)

Call this method to apply a list of actions to a game state. Actions can be `move` or `bear`.
Parameters:
Name Type Description
state State State to change
actionList Array.<MoveAction> List of action to apply.
Overrides:
Source:

bear(state, piece)

Bear piece - remove from board and place outside
Parameters:
Name Type Description
state State Board state
piece Piece Piece to bear
Inherited From:
Source:
Throws:
Throws an error if there is no piece at fromPos or piece is of wrong type

calculateMoveWeights(state, movesLeft, pieceType, rootPiece, stopAtMax) → {Object}

Recursively try out all combinations for the specified player (by piece type) and check the "weight" of each combination. Weight is the sum of all piece movements for a particular combination of moves (called "branch")
Parameters:
Name Type Description
state State State
movesLeft Array.<number> Move values left
pieceType PieceType Type of piece (white/black)
rootPiece Piece Check only branches starting from a specific piece
stopAtMax boolean Stop calculation if a branch that allows all moves to be played has been found.
Inherited From:
Source:
Returns:
- Map containing maximum weight for each branch, indexed by piece ID and total maximum weight for all branches, accessed with 'max' index
Type
Object

countAtHigherPos(state, position, type) → {number}

Count pieces of specified type at higher positions
Parameters:
Name Type Description
state State State to check
position number Normalized position (inclusive)
type PieceType Type of piece (white/black)
Inherited From:
Source:
Returns:
- Number of pieces at positions higher than position
Type
number

denormPos(position, type) → {number}

Get denormalized position - start from 0 to 23 for white player and from 23 to 0 for black player.
Parameters:
Name Type Description
position number Normalized position (0 to 23 for both players)
type PieceType Type of piece (white/black)
Source:
Returns:
- Denormalized position (0 to 23 for white and 23 to 0 for black)
Type
number

(abstract) getGameScore(state, player) → {boolean}

Check game state and determine how much points the player should be awared for this state. If opponent player has not borne any pieces, award 2 points. If opponent has not borne any pieces, and still has pieces in home field of player, award 3 points. In all other cases award 1 point.
Parameters:
Name Type Description
state State Game state
player Player Player
Inherited From:
Source:
Returns:
- True if player has won the game
Type
boolean

getMoveActions(state, piece, type, steps) → {Array.<MoveAction>}

Call this method after a request for moving a piece has been made. Determines if the move is allowed and what actions will have to be made as a result. Actions can be `move` or `bear`. Multiple actions can be returned, if required. The list of actions returned would usually be appllied to game state and then sent to client. The client's UI would play the actions (eg. with movement animation) in the same order.
Parameters:
Name Type Description
state State State
piece Piece Piece to move
type PieceType Type of piece
steps number Number of steps to increment towards first home position
Overrides:
Source:
Returns:
- List of actions if move is allowed, empty list otherwise.
Type
Array.<MoveAction>

(abstract) hasWon(state, player) → {boolean}

Check game state and determine if the specified player has won the game. This method assumes that the specified player was on turn and has played and confirmed his move.
Parameters:
Name Type Description
state State Game state
player Player Player
Inherited From:
Source:
Returns:
- True if player has won the game
Type
boolean

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)
Inherited From:
Source:
Returns:
- True if there are any pieces on the bar
Type
boolean

hit(state, piece)

Hit piece - send piece to bar
Parameters:
Name Type Description
state State Board state
piece Piece Piece to hit
Inherited From:
Source:
Throws:
Throws an error if there is no piece at fromPos or piece is of wrong type

incPos(position, type, steps) → {number}

Increment position by specified number of steps and return an incremented position
Parameters:
Name Type Description
position number Denormalized position
type PieceType Type of piece
steps number Number of steps to increment towards first home position
Overrides:
Source:
Returns:
- Incremented position (denormalized)
Type
number

initialize(state)

Initialize state.
Parameters:
Name Type Description
state State Board state to initialize
Inherited From:
Source:

isMoveActionRestricted(state, movesLeft, piece, steps) → {boolean}

Checks if a specific move action is restricted. If there are any move combinations that would allow the player to use all dice values, then the player is obliged to use one of those combination. If playing both dice values are not possible and the player should choose which one of them to play, they must play the higher value (as long as it is possible).
Parameters:
Name Type Description
state State State
movesLeft Array.<number> Move values left
piece Piece Piece to move
steps number Number of steps to move
Inherited From:
Source:
Returns:
- Returns true if move is restricted (not allowed).
Type
boolean

(abstract) markAsPlayed(game, move)

Mark move as played
Parameters:
Name Type Description
game Game Game
move number Move (number of steps)
Inherited From:
Source:

move(state, piece, toPos)

Move piece to specified point, without enforcing any rules or performing any validation.
Parameters:
Name Type Description
state State Board state
piece Piece Piece to move
toPos number Position to which to move the piece to
Inherited From:
Source:
Throws:
Throws an error if there is no piece at fromPos or piece is of wrong type

(abstract) nextTurn(match)

Proceed to next turn. Start next turn: 1. Reset turn 2. Change players 3. Roll new dice
Parameters:
Name Type Description
match Match Match
Inherited From:
Source:

normPos(position, type) → {number}

Normalize position - Normalized positions start from 0 to 23 for both players, where 0 is the first position in the home part of the board, 6 is the last position in the home part and 23 is the furthest position - in the opponent's home.
Parameters:
Name Type Description
position number Denormalized position (0 to 23 for white and 23 to 0 for black)
type PieceType Type of piece (white/black)
Source:
Returns:
- Normalized position (0 to 23 for both players)
Type
number

place(state, number, type, position)

Place one or more pieces from player set to board point.
Parameters:
Name Type Description
state State Board state
number number Number of pieces to place
type PieceType Type of pieces to place
position number Position at which to place piece(s)
Inherited From:
Source:

recover(state, piece, position)

Recover piece - place from bar to board
Parameters:
Name Type Description
state State Board state
piece Piece Piece to recover
position number Position to which to place the piece
Inherited From:
Source:
Throws:
Throws an error if there is no piece at fromPos or piece is of wrong type

resetState(state)

Reset state to initial position of pieces according to current rule.
Parameters:
Name Type Description
state State Board state
Overrides:
Source:

rollDice(game, valuesopt) → {Dice}

Roll dice and generate list of moves the player has to make according to current rules. Descendants rules would normally override this method in order to properly determine the allowed move values that correspond to a specific die combination (eg. doubles).
Parameters:
Name Type Attributes Description
game Game Game object. Used to check if it is the first turn of the game.
values Array.<number> <optional>
Optional parameter containing the dice values to use, instead of generating random values. Used by some rules as RuleBgGulbara.
Inherited From:
Source:
Returns:
- Dice object containing random values and allowed moves
Type
Dice

validateConfirm(game, player) → {boolean}

Validate confirmation of moves. This is the base method for validation of moves that make a few general checks like: - Is the game started and is finished? - Is it player's turn? - Was dice rolled? - Are all moves played? - Not confirmed already? Descendant rules must extend this method and add additional validation checks according to the rule specifics.
Parameters:
Name Type Description
game Game Game
player Player Player
Inherited From:
Source:
Returns:
True if confirmation is allowed
Type
boolean

validateMove(game, player, piece, steps) → {boolean}

Validate piece move. This is the base method for validation of moves that make a few general checks like: - Is the game started and is finished? - Is it player's turn? - Was dice rolled? - Are moves with values equal to the steps left? Descendant rules must extend this method and add additional validation checks according to the rule specifics.
Parameters:
Name Type Description
game Game Game
player Player Player requesting move
piece Piece Piece to move
steps number Number of steps to make forward to the first home position
Inherited From:
Source:
Returns:
True if move is valid and should be allowed.
Type
boolean

validateTurn(game, player) → {boolean}

Validate player's turn. This is the base method for validation of moves that make a few general checks like: - Is the game started and is finished? - Is it player's turn?
Parameters:
Name Type Description
game Game Game
player Player Player
Inherited From:
Source:
Returns:
True if move is valid and should be allowed.
Type
boolean

validateUndo(game, player) → {boolean}

Validate request for undoing moves. This is the base method for validation of undo that make a few general checks like: - Is the game started and is finished? - Is it player's turn? - Was dice rolled? - Are all moves played? - Not confirmed already? Descendant rules can extend this method and add additional validation checks according to the rule specifics.
Parameters:
Name Type Description
game Game Game
player Player Player
Inherited From:
Source:
Returns:
True if confirmation is allowed
Type
boolean