From 1b3dbd870aaa23b242e617096590ed0f9b90012f Mon Sep 17 00:00:00 2001 From: sorrelbri Date: Mon, 1 Jun 2020 15:58:43 -0700 Subject: [PATCH] add determineTerritory to Game.endGame for empty points --- packages/server/services/Game.js | 278 ++++++++++++++++++++++++++++++- 1 file changed, 275 insertions(+), 3 deletions(-) diff --git a/packages/server/services/Game.js b/packages/server/services/Game.js index 7eb674f..a2a2caa 100644 --- a/packages/server/services/Game.js +++ b/packages/server/services/Game.js @@ -299,10 +299,25 @@ const Game = ({ gameData = {}, gameRecord = [] } = {}) => { // form groups for empty points const joinEmptyPoints = (point) => { if (point.stone) return point; - return point.joinGroup({ point, Game: this }); + point.joinGroup({ point, Game: this }); + return point; }; - const boardState = pipeMap(joinEmptyPoints)(this.boardState); - // for each empty point group determine territory + // for each point determine territory + const determineTerritory = (point) => { + if (point.stone || point.territory) return point; + const points = Array.from(this.groups[point.group].stones); + const neighbors = points.flatMap((pt) => + getNeighbors({ Game: this, point: pt }) + ); + const stones = neighbors.filter((point) => point.stone !== 0); + point.territory = + stones.reduce((acc, { stone }) => acc + stone, 0) || "d"; + return point; + }; + + let boardState = pipeMap(joinEmptyPoints)(this.boardState); + boardState = pipeMap(determineTerritory)(boardState); + this.boardState = boardState; // for each non-empty point group determine life // submit board state to users // if boardState is approved calculate winner @@ -479,3 +494,260 @@ module.exports = { Game, Point, }; + +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");