diff --git a/packages/server/services/Game.js b/packages/server/services/Game.js index cffd3b4..c92f16a 100644 --- a/packages/server/services/Game.js +++ b/packages/server/services/Game.js @@ -382,12 +382,9 @@ const Game = ({ gameData = {}, gameRecord = [] } = {}) => { ); this.playerState.bScore = blackTerritory + this.playerState.bCaptures; this.playerState.wScore = whiteTerritory + this.playerState.wCaptures; - this.score = + const score = this.playerState.bScore - (this.playerState.wScore + this.komi); - this.winner = this.score > 0 ? 1 : -1; - // submit end game board state and data for study - // (study module should run client side and only ) - return { ...this, territory: getTerritory(this) }; + return { ...this, score, winner: score > 0 ? 1 : -1 }; }, }; }; diff --git a/packages/server/test/Game.spec.js b/packages/server/test/Game.spec.js index b0712bb..810f320 100644 --- a/packages/server/test/Game.spec.js +++ b/packages/server/test/Game.spec.js @@ -1019,7 +1019,7 @@ describe("Game end logic", () => { { player: "black", pos: { x: 11, y: 19 } }, ]; const honinboGame = Game({ - gameData: { komi: 4.5 }, + gameData: { komi: 1.5 }, gameRecord: honinboGameRecord, }) .submitPass("white") @@ -1064,10 +1064,20 @@ describe("Game end logic", () => { }); it("end game counts territory properly", (done) => { - const game = honinboGame.endGame(); - // console.log(game.territory); - game.winner.should.eql(1); + const game = honinboGame + .toggleTerritory("6-12") + .toggleTerritory("6-16") + .toggleTerritory("7-6") + .toggleTerritory("7-6") + .toggleTerritory("11-5") + .toggleTerritory("11-5") + .toggleTerritory("11-9") + .toggleTerritory("12-11") + .toggleTerritory("12-11") + .toggleTerritory("16-16") + .endGame(); game.score.should.eql(1.5); + game.winner.should.eql(1); done(); }); });