From 2550d3a36f381f5c312cb3f96f51d6c6557a592e Mon Sep 17 00:00:00 2001 From: Halit Aksoy Date: Sat, 9 Jul 2022 12:46:05 +0300 Subject: [PATCH] fix getWonPlayerId --- src/core/MancalaGame.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/MancalaGame.ts b/src/core/MancalaGame.ts index d613bf2..75a42d3 100644 --- a/src/core/MancalaGame.ts +++ b/src/core/MancalaGame.ts @@ -198,17 +198,18 @@ export class MancalaGame { return false; } - public getWonPlayerId(): string | null { + public getWonPlayerId(): string | undefined { + const player1StoneCount = this.board.player1Bank.stoneCount; + const player2StoneCount = this.board.player2Bank.stoneCount; if (this.checkGameIsEnded()) { - if ( - this.board.player1Bank.stoneCount > this.board.player2Bank.stoneCount - ) { + if (player1StoneCount === player2StoneCount) { + return undefined; + } else if (player1StoneCount > player2StoneCount) { return this.player1Id; } else { return this.player2Id; } } - return null; } public static createFromMancalaGame(mancalaGame: MancalaGame): MancalaGame {