patch endGame scoring bug

This commit is contained in:
sorrelbri 2020-06-05 22:54:19 -07:00
parent 12f9847a0e
commit 49873aa706
2 changed files with 16 additions and 9 deletions

View file

@ -382,12 +382,9 @@ const Game = ({ gameData = {}, gameRecord = [] } = {}) => {
); );
this.playerState.bScore = blackTerritory + this.playerState.bCaptures; this.playerState.bScore = blackTerritory + this.playerState.bCaptures;
this.playerState.wScore = whiteTerritory + this.playerState.wCaptures; this.playerState.wScore = whiteTerritory + this.playerState.wCaptures;
this.score = const score =
this.playerState.bScore - (this.playerState.wScore + this.komi); this.playerState.bScore - (this.playerState.wScore + this.komi);
this.winner = this.score > 0 ? 1 : -1; return { ...this, score, winner: 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) };
}, },
}; };
}; };

View file

@ -1019,7 +1019,7 @@ describe("Game end logic", () => {
{ player: "black", pos: { x: 11, y: 19 } }, { player: "black", pos: { x: 11, y: 19 } },
]; ];
const honinboGame = Game({ const honinboGame = Game({
gameData: { komi: 4.5 }, gameData: { komi: 1.5 },
gameRecord: honinboGameRecord, gameRecord: honinboGameRecord,
}) })
.submitPass("white") .submitPass("white")
@ -1064,10 +1064,20 @@ describe("Game end logic", () => {
}); });
it("end game counts territory properly", (done) => { it("end game counts territory properly", (done) => {
const game = honinboGame.endGame(); const game = honinboGame
// console.log(game.territory); .toggleTerritory("6-12")
game.winner.should.eql(1); .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.score.should.eql(1.5);
game.winner.should.eql(1);
done(); done();
}); });
}); });