-
-
Save slior/66a9102debbfab4613b420db81eab2ea to your computer and use it in GitHub Desktop.
Mancala (38feec5b410f3e30e2701ed8889b1624f8457df0) - fixing a bug in the capturing
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
_checkAndCaptureIfNecessary(lastCell,lastCellWasEmpty) | |
{ | |
let _ = this.board; | |
let isLastCellAHomeCell = _.isPlayer1Home(lastCell) || _.isPlayer2Home(lastCell); | |
let lastCellBelongsToCurrentPlayer = this.player1Playing(_.isPlayer1Cell(lastCell)) || | |
this.player2Playing(_.isPlayer2Cell(lastCell)) | |
if (lastCellWasEmpty && !isLastCellAHomeCell && lastCellBelongsToCurrentPlayer) | |
{ //capture the stones from the other player | |
let acrossCell = _.totalCellCount() - lastCell; | |
let targetHome = this.player == PLAYER.one ? _.player1Home() : _.player2Home(); | |
let totalCapturedStones = _.stonesIn(lastCell) + _.stonesIn(acrossCell); | |
dbg("Capturing stones from " + acrossCell + " and " + lastCell + " to " + targetHome + ". Total: " + totalCapturedStones ) | |
_.setCellStoneCount(targetHome,_.stonesIn(targetHome) + totalCapturedStones); | |
_.setCellStoneCount(acrossCell,0); | |
_.setCellStoneCount(lastCell,0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment