Class

Board

Board(me, rules)

The GameBoard class represents the bawo/bao game board.

The board is represented using 2 circular doubly linked lists each assigned to a player. Each list represents 2 rows with hole Ids assigned as shown below; TOP PLAYER sitting position (facing down) 00 01 02 03 04 05 06 07 15 14 13 12 11 10 09 08 00 01 02 03 04 05 06 07 15 14 13 12 11 10 09 08 BOTTOM PLAYER sitting position (facing up) 32 (optional hole - depends of game version) Rules for Placement of seeds are specified in classes implementing the interface GameRules.

Constructor

# new Board(me, rules)

Parameters:
Name Type Description
me any melonjs instance
rules Rules game rules - default is MtajiModeRules
Author:
  • <a href="http://fumba.me">Fumba Chibaka</a>

View Source core/Board.ts, line 60

Classes

Board

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.

View Source core/Board.ts, line 74

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.

View Source core/Board.ts, line 662

Opposing enemy hole.
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.

View Source core/Board.ts, line 451

true if the capture was successful
boolean

# clone() → {Board}

Clones a board

View Source core/Board.ts, line 725

a clone of the board
Board

# 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

View Source core/Board.ts, line 435

Hole on which the move ends on
Hole

# draw(state) → {void}

Re-renders the state of the hole, HUD, and other UI components on the board
Parameters:
Name Type Description
state

View Source core/Board.ts, line 825

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.

View Source core/Board.ts, line 746

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.

View Source core/Board.ts, line 734

A list of moves that are valid. These moves can be executed on the board.
Array.<Move>

# getCurrentPlayer() → {Player}

Retrieves the current player.

View Source core/Board.ts, line 670

current player
Player

# getOpponentPlayer(player) → {Player}

Retrieves the opponent player for the current player.
Parameters:
Name Type Description
player Player Player whose opponent is to be determined.

View Source core/Board.ts, line 613

opponent player
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.

View Source core/Board.ts, line 793

Opposing enemy hole.
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.

View Source core/Board.ts, line 836

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.

View Source core/Board.ts, line 816

The winning Player.
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.

View Source core/Board.ts, line 806

true if the game is over.
boolean

# isInGraphicsMode() → {boolean}

Checks to see if graphics should be rendered

View Source core/Board.ts, line 763

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.

View Source core/Board.ts, line 708

{@code true} if the move is valid.
boolean

# switchPlayers() → {void}

Switch Players.

View Source core/Board.ts, line 717

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.

View Source core/Board.ts, line 159

# updateMoveStatusForHole(hole)

Updates the move status for the specified hole.
Parameters:
Name Type Description
hole Hole The Hole on will be performed on.

View Source core/Board.ts, line 172

# validateUiState() → {void}

Validates the state of UI entities: 1. There should always be 64 seeds in play (before move and after move)

View Source core/Board.ts, line 755

void