-
-
Save slior/5576c313ca2865ed5e36aa91861c3bf6 to your computer and use it in GitHub Desktop.
Mancala (0c689644b4dc50a85bb7d246bc45531a403cdf79) - Board.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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