add joinEmptyPoints to endGame method on Game

This commit is contained in:
sorrelbri 2020-05-31 23:27:38 -07:00
parent 55a282b5c8
commit 19a5282b73
2 changed files with 266 additions and 3 deletions

View file

@ -297,7 +297,11 @@ const Game = ({ gameData = {}, gameRecord = [] } = {}) => {
endGame: function () { endGame: function () {
// TODO manage territory counting // TODO manage territory counting
// form groups for empty points // form groups for empty points
this.gameRecord; const joinEmptyPoints = (point) => {
if (point.stone) return point;
return point.joinGroup({ point, Game: this });
};
const boardState = pipeMap(joinEmptyPoints)(this.boardState);
// for each empty point group determine territory // for each empty point group determine territory
// for each non-empty point group determine life // for each non-empty point group determine life
// submit board state to users // submit board state to users

View file

@ -765,8 +765,267 @@ describe("Game end logic", () => {
done(); done();
}); });
it("consecutive passes return board state with null stone groups", (done) => { const honinboGameRecord = [
Game({ gameRecord: [] }).initGame(); { player: "black", pos: { x: 4, y: 16 } },
{ player: "white", pos: { x: 3, y: 4 } },
{ player: "black", pos: { x: 16, y: 4 } },
{ player: "white", pos: { x: 17, y: 16 } },
{ player: "black", pos: { x: 15, y: 17 } },
{ player: "white", pos: { x: 5, y: 3 } },
{ player: "black", pos: { x: 17, y: 14 } },
{ player: "white", pos: { x: 16, y: 15 } },
{ player: "black", pos: { x: 16, y: 14 } },
{ player: "white", pos: { x: 14, y: 15 } },
{ player: "black", pos: { x: 15, y: 14 } },
{ player: "white", pos: { x: 14, y: 17 } },
{ player: "black", pos: { x: 14, y: 18 } },
{ player: "white", pos: { x: 13, y: 17 } },
{ player: "black", pos: { x: 16, y: 17 } },
{ player: "white", pos: { x: 15, y: 15 } },
{ player: "black", pos: { x: 13, y: 18 } },
{ player: "white", pos: { x: 11, y: 17 } },
{ player: "black", pos: { x: 17, y: 17 } },
{ player: "white", pos: { x: 18, y: 16 } },
{ player: "black", pos: { x: 12, y: 17 } },
{ player: "white", pos: { x: 12, y: 16 } },
{ player: "black", pos: { x: 12, y: 18 } },
{ player: "white", pos: { x: 16, y: 10 } },
{ player: "black", pos: { x: 17, y: 7 } },
{ player: "white", pos: { x: 13, y: 13 } },
{ player: "black", pos: { x: 15, y: 11 } },
{ player: "white", pos: { x: 11, y: 16 } },
{ player: "black", pos: { x: 15, y: 10 } },
{ player: "white", pos: { x: 16, y: 8 } },
{ player: "black", pos: { x: 17, y: 8 } },
{ player: "white", pos: { x: 15, y: 9 } },
{ player: "black", pos: { x: 17, y: 9 } },
{ player: "white", pos: { x: 16, y: 9 } },
{ player: "black", pos: { x: 13, y: 10 } },
{ player: "white", pos: { x: 16, y: 7 } },
{ player: "black", pos: { x: 16, y: 6 } },
{ player: "white", pos: { x: 15, y: 6 } },
{ player: "black", pos: { x: 16, y: 5 } },
{ player: "white", pos: { x: 13, y: 7 } },
{ player: "black", pos: { x: 11, y: 10 } },
{ player: "white", pos: { x: 13, y: 4 } },
{ player: "black", pos: { x: 3, y: 9 } },
{ player: "white", pos: { x: 10, y: 8 } },
{ player: "black", pos: { x: 9, y: 10 } },
{ player: "white", pos: { x: 7, y: 16 } },
{ player: "black", pos: { x: 4, y: 14 } },
{ player: "white", pos: { x: 8, y: 9 } },
{ player: "black", pos: { x: 8, y: 14 } },
{ player: "white", pos: { x: 8, y: 10 } },
{ player: "black", pos: { x: 9, y: 11 } },
{ player: "white", pos: { x: 8, y: 11 } },
{ player: "black", pos: { x: 10, y: 14 } },
{ player: "white", pos: { x: 9, y: 15 } },
{ player: "black", pos: { x: 12, y: 14 } },
{ player: "white", pos: { x: 11, y: 13 } },
{ player: "black", pos: { x: 12, y: 13 } },
{ player: "white", pos: { x: 12, y: 12 } },
{ player: "black", pos: { x: 13, y: 14 } },
{ player: "white", pos: { x: 14, y: 14 } },
{ player: "black", pos: { x: 11, y: 14 } },
{ player: "white", pos: { x: 14, y: 13 } },
{ player: "black", pos: { x: 14, y: 9 } },
{ player: "white", pos: { x: 12, y: 9 } },
{ player: "black", pos: { x: 12, y: 10 } },
{ player: "white", pos: { x: 16, y: 12 } },
{ player: "black", pos: { x: 16, y: 11 } },
{ player: "white", pos: { x: 17, y: 12 } },
{ player: "black", pos: { x: 18, y: 11 } },
{ player: "white", pos: { x: 18, y: 12 } },
{ player: "black", pos: { x: 15, y: 12 } },
{ player: "white", pos: { x: 15, y: 13 } },
{ player: "black", pos: { x: 17, y: 11 } },
{ player: "white", pos: { x: 15, y: 3 } },
{ player: "black", pos: { x: 16, y: 3 } },
{ player: "white", pos: { x: 16, y: 2 } },
{ player: "black", pos: { x: 17, y: 2 } },
{ player: "white", pos: { x: 3, y: 7 } },
{ player: "black", pos: { x: 5, y: 9 } },
{ player: "white", pos: { x: 8, y: 4 } },
{ player: "black", pos: { x: 5, y: 11 } },
{ player: "white", pos: { x: 4, y: 17 } },
{ player: "black", pos: { x: 3, y: 17 } },
{ player: "white", pos: { x: 5, y: 17 } },
{ player: "black", pos: { x: 3, y: 18 } },
{ player: "white", pos: { x: 5, y: 16 } },
{ player: "black", pos: { x: 4, y: 15 } },
{ player: "white", pos: { x: 15, y: 2 } },
{ player: "black", pos: { x: 4, y: 3 } },
{ player: "white", pos: { x: 4, y: 4 } },
{ player: "black", pos: { x: 10, y: 4 } },
{ player: "white", pos: { x: 8, y: 3 } },
{ player: "black", pos: { x: 12, y: 7 } },
{ player: "white", pos: { x: 13, y: 6 } },
{ player: "black", pos: { x: 5, y: 2 } },
{ player: "white", pos: { x: 4, y: 2 } },
{ player: "black", pos: { x: 10, y: 7 } },
{ player: "white", pos: { x: 9, y: 7 } },
{ player: "black", pos: { x: 10, y: 6 } },
{ player: "white", pos: { x: 12, y: 8 } },
{ player: "black", pos: { x: 9, y: 8 } },
{ player: "white", pos: { x: 10, y: 9 } },
{ player: "black", pos: { x: 8, y: 5 } },
{ player: "white", pos: { x: 9, y: 9 } },
{ player: "black", pos: { x: 6, y: 3 } },
{ player: "white", pos: { x: 5, y: 4 } },
{ player: "black", pos: { x: 7, y: 5 } },
{ player: "white", pos: { x: 6, y: 4 } },
{ player: "black", pos: { x: 12, y: 4 } },
{ player: "white", pos: { x: 11, y: 3 } },
{ player: "black", pos: { x: 12, y: 3 } },
{ player: "white", pos: { x: 10, y: 3 } },
{ player: "black", pos: { x: 14, y: 4 } },
{ player: "white", pos: { x: 15, y: 4 } },
{ player: "black", pos: { x: 13, y: 5 } },
{ player: "white", pos: { x: 15, y: 5 } },
{ player: "black", pos: { x: 9, y: 4 } },
{ player: "white", pos: { x: 9, y: 3 } },
{ player: "black", pos: { x: 7, y: 7 } },
{ player: "white", pos: { x: 12, y: 6 } },
{ player: "black", pos: { x: 11, y: 4 } },
{ player: "white", pos: { x: 8, y: 8 } },
{ player: "black", pos: { x: 6, y: 8 } },
{ player: "white", pos: { x: 2, y: 8 } },
{ player: "black", pos: { x: 2, y: 9 } },
{ player: "white", pos: { x: 9, y: 12 } },
{ player: "black", pos: { x: 10, y: 12 } },
{ player: "white", pos: { x: 10, y: 10 } },
{ player: "black", pos: { x: 10, y: 11 } },
{ player: "white", pos: { x: 9, y: 13 } },
{ player: "black", pos: { x: 9, y: 14 } },
{ player: "white", pos: { x: 10, y: 13 } },
{ player: "black", pos: { x: 11, y: 11 } },
{ player: "white", pos: { x: 7, y: 13 } },
{ player: "black", pos: { x: 7, y: 14 } },
{ player: "white", pos: { x: 6, y: 13 } },
{ player: "black", pos: { x: 6, y: 14 } },
{ player: "white", pos: { x: 5, y: 13 } },
{ player: "black", pos: { x: 8, y: 13 } },
{ player: "white", pos: { x: 8, y: 12 } },
{ player: "black", pos: { x: 6, y: 11 } },
{ player: "white", pos: { x: 7, y: 11 } },
{ player: "black", pos: { x: 6, y: 15 } },
{ player: "white", pos: { x: 14, y: 8 } },
{ player: "black", pos: { x: 19, y: 12 } },
{ player: "white", pos: { x: 19, y: 13 } },
{ player: "black", pos: { x: 18, y: 13 } },
{ player: "white", pos: { x: 19, y: 11 } },
{ player: "black", pos: { x: 19, y: 14 } },
{ player: "white", pos: { x: 16, y: 13 } },
{ player: "black", pos: { x: 19, y: 12 } },
{ player: "white", pos: { x: 13, y: 15 } },
{ player: "black", pos: { x: 11, y: 18 } },
{ player: "white", pos: { x: 10, y: 18 } },
{ player: "black", pos: { x: 19, y: 10 } },
{ player: "white", pos: { x: 8, y: 18 } },
{ player: "black", pos: { x: 5, y: 19 } },
{ player: "white", pos: { x: 13, y: 9 } },
{ player: "black", pos: { x: 14, y: 10 } },
{ player: "white", pos: { x: 18, y: 18 } },
{ player: "black", pos: { x: 18, y: 17 } },
{ player: "white", pos: { x: 19, y: 17 } },
{ player: "black", pos: { x: 17, y: 18 } },
{ player: "white", pos: { x: 8, y: 15 } },
{ player: "black", pos: { x: 4, y: 13 } },
{ player: "white", pos: { x: 17, y: 1 } },
{ player: "black", pos: { x: 18, y: 2 } },
{ player: "white", pos: { x: 1, y: 9 } },
{ player: "black", pos: { x: 1, y: 10 } },
{ player: "white", pos: { x: 1, y: 8 } },
{ player: "black", pos: { x: 2, y: 10 } },
{ player: "white", pos: { x: 9, y: 6 } },
{ player: "black", pos: { x: 9, y: 5 } },
{ player: "white", pos: { x: 6, y: 6 } },
{ player: "black", pos: { x: 8, y: 7 } },
{ player: "white", pos: { x: 5, y: 7 } },
{ player: "black", pos: { x: 6, y: 18 } },
{ player: "white", pos: { x: 7, y: 18 } },
{ player: "black", pos: { x: 10, y: 19 } },
{ player: "white", pos: { x: 9, y: 19 } },
{ player: "black", pos: { x: 9, y: 17 } },
{ player: "white", pos: { x: 11, y: 19 } },
{ player: "black", pos: { x: 19, y: 18 } },
{ player: "white", pos: { x: 4, y: 19 } },
{ player: "black", pos: { x: 4, y: 18 } },
{ player: "white", pos: { x: 5, y: 18 } },
{ player: "black", pos: { x: 3, y: 19 } },
{ player: "white", pos: { x: 6, y: 17 } },
{ player: "black", pos: { x: 19, y: 16 } },
{ player: "white", pos: { x: 11, y: 2 } },
{ player: "black", pos: { x: 12, y: 2 } },
{ player: "white", pos: { x: 14, y: 5 } },
{ player: "black", pos: { x: 13, y: 3 } },
{ player: "white", pos: { x: 6, y: 10 } },
{ player: "black", pos: { x: 3, y: 8 } },
{ player: "white", pos: { x: 2, y: 7 } },
{ player: "black", pos: { x: 5, y: 10 } },
{ player: "white", pos: { x: 18, y: 15 } },
{ player: "black", pos: { x: 19, y: 15 } },
{ player: "white", pos: { x: 6, y: 19 } },
{ player: "black", pos: { x: 12, y: 19 } },
{ player: "white", pos: { x: 18, y: 1 } },
{ player: "black", pos: { x: 10, y: 19 } },
{ player: "white", pos: { x: 9, y: 18 } },
{ player: "black", pos: { x: 10, y: 15 } },
{ player: "white", pos: { x: 10, y: 16 } },
{ player: "black", pos: { x: 19, y: 2 } },
{ player: "white", pos: { x: 18, y: 14 } },
{ player: "black", pos: { x: 17, y: 13 } },
{ player: "white", pos: { x: 6, y: 9 } },
{ player: "black", pos: { x: 7, y: 9 } },
{ player: "white", pos: { x: 7, y: 10 } },
{ player: "black", pos: { x: 5, y: 8 } },
{ player: "white", pos: { x: 7, y: 8 } },
{ player: "black", pos: { x: 6, y: 7 } },
{ player: "white", pos: { x: 4, y: 7 } },
{ player: "black", pos: { x: 6, y: 5 } },
{ player: "white", pos: { x: 5, y: 5 } },
{ player: "black", pos: { x: 7, y: 4 } },
{ player: "white", pos: { x: 7, y: 3 } },
{ player: "black", pos: { x: 11, y: 7 } },
{ player: "white", pos: { x: 4, y: 8 } },
{ player: "black", pos: { x: 4, y: 9 } },
{ player: "white", pos: { x: 5, y: 12 } },
{ player: "black", pos: { x: 4, y: 12 } },
{ player: "white", pos: { x: 17, y: 10 } },
{ player: "black", pos: { x: 18, y: 10 } },
{ player: "white", pos: { x: 15, y: 16 } },
{ player: "black", pos: { x: 12, y: 5 } },
{ player: "white", pos: { x: 11, y: 6 } },
{ player: "black", pos: { x: 14, y: 2 } },
{ player: "white", pos: { x: 14, y: 3 } },
{ player: "black", pos: { x: 11, y: 1 } },
{ player: "white", pos: { x: 10, y: 1 } },
{ player: "black", pos: { x: 12, y: 1 } },
{ player: "white", pos: { x: 17, y: 15 } },
{ player: "black", pos: { x: 19, y: 13 } },
{ player: "white", pos: { x: 17, y: 3 } },
{ player: "black", pos: { x: 18, y: 3 } },
{ player: "white", pos: { x: 11, y: 8 } },
{ player: "black", pos: { x: 10, y: 5 } },
{ player: "white", pos: { x: 14, y: 1 } },
{ player: "black", pos: { x: 13, y: 1 } },
{ player: "white", pos: { x: 13, y: 12 } },
{ player: "black", pos: { x: 15, y: 1 } },
{ player: "white", pos: { x: 16, y: 1 } },
{ player: "black", pos: { x: 14, y: 1 } },
{ player: "white", pos: { x: 4, y: 19 } },
{ player: "black", pos: { x: 13, y: 4 } },
{ player: "white", pos: { x: 5, y: 19 } },
{ player: "black", pos: { x: 11, y: 19 } },
];
const honinboGame = Game({ gameRecord: honinboGameRecord })
.submitPass("white")
.submitPass("black");
it("consecutive passes return board state with empty points in groups", (done) => {
honinboGame.boardState["1-1"].group.should.not.eql(null);
const group = honinboGame.boardState["19-5"].group;
honinboGame.boardState["17-4"].group.should.eql(group);
done(); done();
}); });
}); });