private int ClaimRegion(ref char[,] board, ref List <ChronalCoordinate> points) { int rowLength = board.GetLength(0); int colLength = board.GetLength(1); int minimumDistance = (_runExample) ? 32 : 10000; int regionSize = 0; for (int i = 0; i < rowLength; i++) { for (int j = 0; j < colLength; j++) { var distanceToPoints = new List <int>(); // loop the points foreach (var coord in points) { int distance = Heuristics.ManhattanDistance(j, coord.X, i, coord.Y); distanceToPoints.Add(distance); } // check if all the distances are under the minimum if (distanceToPoints.Sum() < minimumDistance) { regionSize++; board[i, j] = (board[i, j] == '.') ? '#' : board[i, j]; } } } return(regionSize); }
private Dictionary <char, int> ClaimBoard(ref char[,] board, ref List <ChronalCoordinate> points) { int rowLength = board.GetLength(0); int colLength = board.GetLength(1); var claimCoverage = new Dictionary <char, int>(); for (int i = 0; i < rowLength; i++) { for (int j = 0; j < colLength; j++) { var claims = new Dictionary <char, int>(); foreach (var coord in points) { int distance = Heuristics.ManhattanDistance(coord.X, j, coord.Y, i); claims.Add(coord.Id, distance); } int closestValue = claims.Values.Min(); if (claims.Values.Where(x => x == closestValue).Count() <= 1) { // we have exactly 1 closest claim! char id = claims.Where(x => x.Value == closestValue).FirstOrDefault().Key; board[i, j] = id; // add to our claim coverage if (!claimCoverage.ContainsKey(id)) { claimCoverage.Add(id, 1); } else { claimCoverage[id]++; } } } } var finiteClaims = new Dictionary <char, int>(); foreach (var point in points.OrderBy(x => x.Id)) { // check if we are around the boundaries of our board if (board.GetRow(0).Contains(point.Id) || board.GetRow(rowLength - 1).Contains(point.Id) || board.GetCol(0).Contains(point.Id) || board.GetCol(colLength - 1).Contains(point.Id)) { // set finite to false, it's impossible for this point to be finite because we assume outside the boundaries of our board is infinity! point.IsFinite = false; continue; } // check to see if we have any claims at all? if (!claimCoverage.ContainsKey(point.Id)) { point.IsFinite = false; continue; } // now we need to check the ones we know could be finite. // in the example only D & E should get to this point point.IsFinite = true; // test, this will be changed? finiteClaims.Add(point.Id, claimCoverage[point.Id]); } return(finiteClaims); }