bug fix stopIndex%circle.length

This commit is contained in:
jhalitaksoy 2021-07-03 18:56:27 +03:00
parent fabc2ce07d
commit fb12557ed7
2 changed files with 12 additions and 1 deletions

View File

@ -74,7 +74,7 @@ export class Game {
//check if it was 0 before //check if it was 0 before
if (stopHole.ballCount == 1) { if (stopHole.ballCount == 1) {
const ownStore = getOwnStore(circle) const ownStore = getOwnStore(circle)
const opponentHole = getOpponentHoleByIndex(stopIndex%16, circle) const opponentHole = getOpponentHoleByIndex(stopIndex%circle.length, circle)
if (opponentHole.ballCount > 0) { if (opponentHole.ballCount > 0) {
ownStore.ballCount++ ownStore.ballCount++

View File

@ -47,4 +47,15 @@ describe('mancala', function () {
expect(game.state).toBe("ended") expect(game.state).toBe("ended")
expect(game.getWonPlayer()).toBe("player2") expect(game.getWonPlayer()).toBe("player2")
}) })
it('too many ball test', function () {
const board = new Board(
[new Hole(1), new Hole(1), new Hole(1), new Hole(1), new Hole(1), new Hole(1)],
[new Hole(0), new Hole(0), new Hole(0), new Hole(0), new Hole(0), new Hole(12)],
new Store(0), new Store(0))
const game = new Game(player1, player2, board, "player2", "playing")
game.moveByIndex(5, "player2")
expect(game.turn).toBe("player1")
expect(game.state).toBe("playing")
})
}) })