From 52e14c7e045abbdedd519c8b14cbec14dc513c22 Mon Sep 17 00:00:00 2001 From: Halit Aksoy Date: Wed, 4 May 2022 15:04:01 +0300 Subject: [PATCH] add GrClearBoardAtEnd game rule --- src/common/game_rules/GRClearBoardAtEnd.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/common/game_rules/GRClearBoardAtEnd.ts diff --git a/src/common/game_rules/GRClearBoardAtEnd.ts b/src/common/game_rules/GRClearBoardAtEnd.ts new file mode 100644 index 0000000..caa2a55 --- /dev/null +++ b/src/common/game_rules/GRClearBoardAtEnd.ts @@ -0,0 +1,17 @@ +import { GameRule } from '../../core/GameRule'; +import { MancalaGame } from '../../core/MancalaGame'; + +export class GRClearBoardAtEnd implements GameRule { + onGameMoveStart(game: MancalaGame, index: number): void {} + onGameMove(game: MancalaGame, index: number): void {} + onGameMoveEnd(game: MancalaGame, index: number): void { + if (game.getPlayer1StoneCountInPits() === 0) { + game.board.player1Bank.stoneCount += game.getPlayer2StoneCountInPits(); + game.board.clearPlayer2Pits(); + } + if (game.getPlayer2StoneCountInPits() === 0) { + game.board.player2Bank.stoneCount += game.getPlayer1StoneCountInPits(); + game.board.clearPlayer1Pits(); + } + } +}