From 19a5282b73073b2c93862990dbcc4e1bb5e26ca0 Mon Sep 17 00:00:00 2001 From: sorrelbri Date: Sun, 31 May 2020 23:27:38 -0700 Subject: [PATCH] add joinEmptyPoints to endGame method on Game --- packages/server/services/Game.js | 6 +- packages/server/test/Game.spec.js | 263 +++++++++++++++++++++++++++++- 2 files changed, 266 insertions(+), 3 deletions(-) diff --git a/packages/server/services/Game.js b/packages/server/services/Game.js index 5537d5e..7eb674f 100644 --- a/packages/server/services/Game.js +++ b/packages/server/services/Game.js @@ -297,7 +297,11 @@ const Game = ({ gameData = {}, gameRecord = [] } = {}) => { endGame: function () { // TODO manage territory counting // 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 non-empty point group determine life // submit board state to users diff --git a/packages/server/test/Game.spec.js b/packages/server/test/Game.spec.js index aa0c685..c55e33b 100644 --- a/packages/server/test/Game.spec.js +++ b/packages/server/test/Game.spec.js @@ -765,8 +765,267 @@ describe("Game end logic", () => { done(); }); - it("consecutive passes return board state with null stone groups", (done) => { - Game({ gameRecord: [] }).initGame(); + const honinboGameRecord = [ + { 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(); }); });