diff --git a/src/mancala.ts b/src/mancala.ts index 7eea963..5eee132 100644 --- a/src/mancala.ts +++ b/src/mancala.ts @@ -74,7 +74,7 @@ export class Game { //check if it was 0 before if (stopHole.ballCount == 1) { const ownStore = getOwnStore(circle) - const opponentHole = getOpponentHoleByIndex(stopIndex%16, circle) + const opponentHole = getOpponentHoleByIndex(stopIndex%circle.length, circle) if (opponentHole.ballCount > 0) { ownStore.ballCount++ diff --git a/tests/mancala.test.ts b/tests/mancala.test.ts index 1f3ed69..67aced8 100644 --- a/tests/mancala.test.ts +++ b/tests/mancala.test.ts @@ -47,4 +47,15 @@ describe('mancala', function () { expect(game.state).toBe("ended") 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") + }) }) \ No newline at end of file