Skip to content

Instantly share code, notes, and snippets.

@slior

slior/board.js Secret

Created November 1, 2020 12:13
Show Gist options
  • Save slior/5576c313ca2865ed5e36aa91861c3bf6 to your computer and use it in GitHub Desktop.
Save slior/5576c313ca2865ed5e36aa91861c3bf6 to your computer and use it in GitHub Desktop.
Mancala (0c689644b4dc50a85bb7d246bc45531a403cdf79) - Board.js
class Board
{
constructor(_cellCount)
{
this.cellCount = _cellCount;
this.board = [];
range(1,this.cellCount).forEach(_ => this.board.push(0))
this.forAllPlayer1Cells(cellInd => this.setCellStoneCount(cellInd,INITIAL_STONE_COUNT))
this.forAllPlayer2Cells(cellInd => this.setCellStoneCount(cellInd,INITIAL_STONE_COUNT))
dbg("Board initialized")
}
forAllPlayer2Cells(f) { ... }
forAllPlayer1Cells(f) { ... }
setCellStoneCount(boardCell,cnt) { this.board[boardCell] = cnt }
stonesIn(boardCell) { return this.board[boardCell]}
forAllCells(f) { ... }
isPlayer1Cell(boardCell) { return boardCell >= 1 && boardCell <= this.cellCount/2-1; }
isPlayer2Cell(boardCell) { return boardCell >= this.cellCount/2+1 && boardCell <= this.cellCount-1; }
isPlayer1Home(boardCell) { return boardCell == 0; }
isPlayer2Home(boardCell) { return boardCell == this.cellCount/2; }
totalCellCount() { return this.cellCount; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment