Constructor
# new Board(me, rules)
Parameters:
Name | Type | Description |
---|---|---|
me |
any
|
melonjs instance |
rules |
Rules
|
game rules - default is MtajiModeRules |
Classes
Members
# isInContinuousLoopStatus
The game play is in a continuous loop if the player continues to play beyond a
threshold amount of moves.
The game will end and the player who got themselves into an infinite loop will lose.
Methods
# adjacentOpponentHole(hole) → {Hole}
Extract the opposing enemy hole from the players front row.
This is hole from which the current player will be capturing seeds from.
Parameters:
Name | Type | Description |
---|---|---|
hole |
Hole
|
Hole from which the opposing enemy hole is to be retrieved from. |
Opposing enemy hole.
# captureAllSeedsFromEnemy(startHole) → {boolean}
Capture all seeds from enemy if current player stopped on front row.
Parameters:
Name | Type | Description |
---|---|---|
startHole |
Hole
|
The hole which will be capturing the enemy seeds. |
true if the capture was successful
boolean
# computeDestinationHole(direction, hole, numberOfSteps) → {Hole}
Finds the hole on which planting the given number of seed tokens one by one-
will stop when executed.
Parameters:
Name | Type | Description |
---|---|---|
direction |
MoveDirection
|
Direction of the move |
hole |
Hole
|
The hole on which the move starts on |
numberOfSteps |
number
|
Number of seeds to be planted in the move |
Hole on which the move ends on
# draw(state) → {void}
Re-renders the state of the hole, HUD, and other UI components on the board
Parameters:
Name | Type | Description |
---|---|---|
state |
void
# executeMove(move) → {boolean}
Execute a move:
The rules on how the move is to be performed are specified in the
implementation of the GameRules interface.
Parameters:
Name | Type | Description |
---|---|---|
move |
Move
|
The move to be executed. |
A boolean value representing whether or not the move was successful.
boolean
# getAllAvailableValidMoves(player) → {Array.<Move>}
Retrieves all the valid moves for a player.
Parameters:
Name | Type | Description |
---|---|---|
player |
Player
|
The Player who is requesting the list of valid moves. |
A list of moves that are valid. These moves can be executed on the board.
Array.<Move>
# getOpponentPlayer(player) → {Player}
Retrieves the opponent player for the current player.
Parameters:
Name | Type | Description |
---|---|---|
player |
Player
|
Player whose opponent is to be determined. |
opponent player
# getOpposingEnemyHole(hole) → {Hole}
Extract the opposing enemy hole from the players front row.
Parameters:
Name | Type | Description |
---|---|---|
hole |
Hole
|
Hole from which the opposing enemy hole is to be retrieved. |
Opposing enemy hole.
# getScore() → {number}
Calculates the current game score. The score is calculated as the number
seeds on the player side. If a player gets themselves into an infinite loop
move, they have lost the game.
A Hash with the PlayerSide as the key and the number of seeds on that
side as the value.
number
# getWinningPlayer() → {Player}
Gets the player who won the game. This only happens if the game is over.
opposing player is determined as the winning player since the current player
cannot make any moves in this case.
The winning Player.
# isGameOver() → {boolean}
Checks if the game is over. The game is over if the current player is left
with no valid moves (ie. all the moves are locked).
When the game play gets in an infinite loop, the game is also considered be
over. The player who gets themselves into the loop is considered to have lost
the game in this case.
true if the game is over.
boolean
# isInGraphicsMode() → {boolean}
Checks to see if graphics should be rendered
if graphics need to be rendered
boolean
# isValidMove(move) → {boolean}
Check if a move valid. GameRules implementation is used to make this
decision.
Parameters:
Name | Type | Description |
---|---|---|
move |
Move
|
The move whose validity is to be checked. |
{@code true} if the move is valid.
boolean
# switchPlayers() → {void}
Switch Players.
Error when an attempt is made to switch while one of the players has seeds in hands.
void
# updateMovesStatus()
Update the move status for all the holes on the board.
Move Status can be one of the following:
CLOCKWISE
ANTI_CLOCKWISE
BOTH - Both clockwise and anti-clockwise moves are allowed.
LOCKED - A valid move cannot be made from the hole.
UNAUTHORIZED - The hole does not belong to the current player.
# updateMoveStatusForHole(hole)
Updates the move status for the specified hole.
Parameters:
Name | Type | Description |
---|---|---|
hole |
Hole
|
The Hole on will be performed on. |
# validateUiState() → {void}
Validates the state of UI entities:
1. There should always be 64 seeds in play (before move and after move)
void