public ResponseBase CookRes(int[,] brd) { RegularGoCountingResponse res = new RegularGoCountingResponse(); res.board = new Board(); res.board = seResponseSealed.board; int n = res.board.n; List <Move> deadStones = ScoreEstimatorLogic.GetDeadStones(this.userTouches, res.board.whites, res.board.blacks, res.board.n); res.dead = deadStones; for (int i = 0; i < deadStones.Count; i++) { brd[deadStones[i].x, deadStones[i].y] = 0; } double[,] map = null; if (CreateNewGamePopup.GetSelection(modePopup) == 0) { /* * UnityEngine.Debug.Log(Utils.Measure(delegate { * double[,] d = ScoreEstimatorLogic.CountTerritory(brd); * Console.WriteLine("f**k"); * })); * UnityEngine.Debug.Log(Utils.Measure(delegate { * double[,] d = ScoreEstimatorLogic.CountTerritoryC(brd); * Console.WriteLine("f**k"); * })); */ map = ScoreEstimatorLogic.CountTerritory(brd); } else { map = ScoreEstimatorLogic.CountInfluence(brd); } double limit = 0.01; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { bool contains = false; for (int k = 0; k < seResponseSealed.board.blacks.Count; k++) { if (seResponseSealed.board.blacks[k].x == i && seResponseSealed.board.blacks[k].y == j) { contains = true; } } for (int k = 0; k < seResponseSealed.board.whites.Count; k++) { if (seResponseSealed.board.whites[k].x == i && seResponseSealed.board.whites[k].y == j) { contains = true; } } if (!contains) { if (brd[i, j] == 0 && map[i, j] > limit) { res.whiteTerritory.Add(new Move(i, j)); res.whiteTerritorySize.Add(map[i, j]); } if (brd[i, j] == 0 && map[i, j] < -limit) { res.blackTerritory.Add(new Move(i, j)); res.blackTerritorySize.Add(-map[i, j]); } } } } double whiteScore = 0; double blackScore = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (map[i, j] > 0) { whiteScore += map[i, j]; } else { blackScore += -map[i, j]; } } } whiteScore += seResponseSealed.komi1 + seResponseSealed.komi2; double diff = blackScore - whiteScore; if (diff > 0) { diffLabel.text = "B+" + Math.Round(diff, 0); } else { diffLabel.text = "W+" + Math.Round(-diff, 0); } this.whiteScore.text = Math.Round(whiteScore, 0) + ""; this.blackScore.text = Math.Round(blackScore, 0) + ""; return(res); }
public static ResponseBase Parse(string str, int index) { ResponseBase res = null; ResponseJson rj = JsonConvert.DeserializeObject <ResponseJson>(str); string phase = rj.phase; int boardSize = rj.n; int nPlayers = 2; string gameTitle = rj.title; string boardContent = rj.board; Board board = new Board(); board.n = boardSize; int cnt = 0; for (int i = 0; i < boardSize; i++) { for (int j = 0; j < boardSize; j++) { int val = (int)(boardContent[cnt] - '0'); if (val != 9) { if (val == rj.black_player) { board.blacks.Add(new Move(i, j)); } else { board.whites.Add(new Move(i, j)); } } cnt++; } } if (phase == "game") { bool ask = rj.asking == 1; int rev1 = rj.rev1; int rev2 = rj.rev2; String time1 = rj.time1; String time2 = rj.time2; if (gameTitle.Equals("go")) { res = new RegularGoGameResponse(); } if (gameTitle.Equals("one-color-go")) { res = new OneColorGoGameResponse(); ((OneColorGoGameResponse)res).isAsking = ask; ((OneColorGoGameResponse)res).reveal1 = rev1; ((OneColorGoGameResponse)res).reveal2 = rev2; } if (gameTitle.Equals("blind-go")) { res = new BlindGoGameResponse(); ((BlindGoGameResponse)res).isAsking = ask; ((BlindGoGameResponse)res).reveal1 = rev1; ((BlindGoGameResponse)res).reveal2 = rev2; } if (gameTitle.Equals("hidden-move-go")) { string[] cont = rj.hidden_moves; res = new HiddenMoveGoGameResponse(); ParseHiddenMoves(res, rj); } if (!rj.last_move.Equals("nada")) { string lastMove = rj.last_move; string[] ps = lastMove.Split('-'); int a = int.Parse(ps[0]); int b = int.Parse(ps[1]); Move lm = new Move(a, b); ((GameResponse)res).lastMove = lm; } ((GameResponse)res).time1 = rj.time1; ((GameResponse)res).time2 = rj.time2; ((GameResponse)res).current = rj.current; } if (phase == "counting") { string lifeTableContent = rj.life_table; List <Move> dead = new List <Move>(); bool[,] lifeTable = new bool[boardSize, boardSize]; cnt = 0; for (int i = 0; i < boardSize; i++) { for (int j = 0; j < boardSize; j++) { lifeTable[i, j] = (lifeTableContent[cnt] == '0'); if (lifeTable[i, j]) { dead.Add(new Move(i, j)); } cnt++; } } string countingTableContent = rj.territory_table; List <Move> whiteTerritory = new List <Move>(); List <Move> blackTerritory = new List <Move>(); List <double> whiteTerritorySize = new List <double>(); List <double> blackTerritorySize = new List <double>(); cnt = 0; for (int i = 0; i < boardSize; i++) { for (int j = 0; j < boardSize; j++) { if (countingTableContent[cnt] != '9') { if (countingTableContent[cnt] == '0' && rj.black_player == 0) { blackTerritory.Add(new Move(i, j)); blackTerritorySize.Add(1.0); } if (countingTableContent[cnt] == '1' && rj.black_player == 1) { blackTerritory.Add(new Move(i, j)); blackTerritorySize.Add(1.0); } if (countingTableContent[cnt] == '0' && rj.black_player == 1) { whiteTerritory.Add(new Move(i, j)); whiteTerritorySize.Add(1.0); } if (countingTableContent[cnt] == '1' && rj.black_player == 0) { whiteTerritory.Add(new Move(i, j)); whiteTerritorySize.Add(1.0); } } cnt++; } } if (gameTitle.Equals("go")) { res = new RegularGoCountingResponse(); ((RegularGoCountingResponse)res).dead = dead; ((RegularGoCountingResponse)res).whiteTerritory = whiteTerritory; ((RegularGoCountingResponse)res).blackTerritory = blackTerritory; ((RegularGoCountingResponse)res).whiteTerritorySize = whiteTerritorySize; ((RegularGoCountingResponse)res).blackTerritorySize = blackTerritorySize; } if (gameTitle.Equals("one-color-go")) { res = new OneColorGoCountingResponse(); ((OneColorGoCountingResponse)res).dead = dead; ((OneColorGoCountingResponse)res).whiteTerritory = whiteTerritory; ((OneColorGoCountingResponse)res).blackTerritory = blackTerritory; ((OneColorGoCountingResponse)res).whiteTerritorySize = whiteTerritorySize; ((OneColorGoCountingResponse)res).blackTerritorySize = blackTerritorySize; } if (gameTitle.Equals("blind-go")) { res = new BlindGoCountingResponse(); ((BlindGoCountingResponse)res).dead = dead; ((BlindGoCountingResponse)res).whiteTerritory = whiteTerritory; ((BlindGoCountingResponse)res).blackTerritory = blackTerritory; ((BlindGoCountingResponse)res).whiteTerritorySize = whiteTerritorySize; ((BlindGoCountingResponse)res).blackTerritorySize = blackTerritorySize; } if (gameTitle.Equals("hidden-move-go")) { res = new HiddenMoveGoCountingResponse(); ((HiddenMoveGoCountingResponse)res).dead = dead; ((HiddenMoveGoCountingResponse)res).whiteTerritory = whiteTerritory; ((HiddenMoveGoCountingResponse)res).blackTerritory = blackTerritory; ((HiddenMoveGoCountingResponse)res).whiteTerritorySize = whiteTerritorySize; ((HiddenMoveGoCountingResponse)res).blackTerritorySize = blackTerritorySize; } } if (phase.Equals("setup")) { if (gameTitle.Equals("hidden-move-go")) { res = new HiddenMoveGoSetupResponse(); HiddenMoveGoSetupResponse tr = ((HiddenMoveGoSetupResponse)res); tr.total = rj.hm_count; ParseHiddenMoves(tr, rj); for (int i = 0; i < tr.colors.Count; i++) { if (tr.colors[i] == index) { tr.placed++; } } } } if (rj.black_player == index) { res.me = MeEnum.BLACK; } if (rj.black_player == 1 - index) { res.me = MeEnum.WHITE; } if (index == 9) { res.me = MeEnum.OBSERVER; } res.board = board; res.black = rj.black_player; res.komi1 = rj.komi1; res.komi2 = rj.komi2; if (res is RevealableGameResponse) { ((RevealableGameResponse)res).isRevealed = rj.is_revealed; } res.handi = rj.handi; Dump(res); return(res); }