public static void Day6b() { string line; string[] lineSplit; List <Core.Point> destinations = new List <Core.Point>(); using (Stream stream = thisExe.GetManifestResourceStream("AdventOfCode2018._data.AdventOfCode_Day6.txt")) using (StreamReader reader = new StreamReader(stream)) { while ((line = reader.ReadLine()) != null) { lineSplit = line.RemoveWhitespace().Split(','); Core.Point point = new Core.Point(Convert.ToInt32(lineSplit[0]), Convert.ToInt32(lineSplit[1])); destinations.Add(point); } } int maxX = (destinations.OrderBy(d => d.X).LastOrDefault()).X + 1; int maxY = (destinations.OrderBy(d => d.Y).LastOrDefault()).Y + 1; char[,] validPartOfZone = new char[maxX, maxY]; int goodPointCount = 0; for (int y = 0; y < maxY; y++) { for (int x = 0; x < maxX; x++) { validPartOfZone[x, y] = CoordinateGeometry.CheckManhattanDistances(x, y, destinations, 10000); if (validPartOfZone[x, y] == 'X') { goodPointCount++; } } } /* * StringBuilder sb = new StringBuilder(); * * for (int i = 0; i < validPartOfZone.GetLength(0); i++) * { * for (int ii = 0; ii < validPartOfZone.GetLength(1); ii++) * { * sb.Append(validPartOfZone[i, ii].ToString().PadLeft(2)); * } * * sb.Append(Environment.NewLine); * } * * File.WriteAllText("validzone.txt", sb.ToString()); */ MessageBox.Show(goodPointCount.ToString()); }
public Player GetClosestEnemy(List <Player> players) { List <Player> _ret = new List <Player>(); int distance = 999999999; int _dst; foreach (Player e in players.Where(w => w.side == this.enemy)) { if ((_dst = CoordinateGeometry.CheckManhattanDistance(this.Location, e.Location)) == distance) { distance = _dst; _ret.Add(e); } else if ((_dst = CoordinateGeometry.CheckManhattanDistance(this.Location, e.Location)) < distance) { distance = _dst; _ret.Clear(); _ret.Add(e); } } return(_ret.OrderBy(o => o.Location.Y).ThenBy(o => o.Location.X).FirstOrDefault()); }