void Awake() { float baseX = -width / 2.0f + 0.5f; float baseY = -height / 2.0f + 0.5f; Dictionary <Point, Constituent> locationDict = new Dictionary <Point, Constituent>(); //create each constituent Constituents = new List <Constituent>(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Vector3 position = new Vector3(baseX + x, baseY + y, 0.0f); var constituent = MakeConstituent(position); locationDict.Add(new Point(x, y), constituent); Constituents.Add(constituent); } } //assign neighbors to each constistuent foreach (Point p in locationDict.Keys) { Constituent c = locationDict[p]; Constituent top, bottom, left, right; locationDict.TryGetValue(p + new Point(0, 1), out top); locationDict.TryGetValue(p + new Point(0, -1), out bottom); locationDict.TryGetValue(p + new Point(-1, 0), out left); locationDict.TryGetValue(p + new Point(1, 0), out right); c.SetNeighbors(top, bottom, left, right); } if (setupString.Length > 0) { ParseCity(setupString); foreach (District d in Districts) { d.UpdateMemberData(); } } else { PartitionCity(Constituents); foreach (District d in Districts) { d.UpdateMemberData(); } //balance pass: make sure there are an equal number of red and blue constituents BalanceConstituentCounts(); //balance pass: make sure there are an equal number of red and blue districts BalanceDistrictCounts(); } float averageDistrictSize = (float)Constituents.Count((c) => { return(c.party != Constituent.Party.None); }) / numDistricts; MinDistrictSize = (int)System.Math.Round(averageDistrictSize * 0.75f); foreach (Constituent c in Constituents) { c.UpdateBorders(); } }