public Day17(List <string> d) { grid1 = new Grid3D(d[0].Length - 1, d.Count - 1, 0); grid2 = new Grid4D(d[0].Length - 1, d.Count - 1, 0, 0); int y = 0; foreach (string s in d) { int x = 0; foreach (char c in s) { Cord3D cord = new Cord3D(x, y, 0); Cord4D cord2 = new Cord4D(x, y, 0, 0); Node n; Node m; if (c == '#') { n = new Node(true); m = new Node(true); } else { n = new Node(false); m = new Node(false); } grid1.AddNode(cord, n); grid2.AddNode(cord2, m); x++; } y++; } }
public void AddNode(Cord3D c, Node n) { foreach (Cord3D co in c.GetNeighbourCords()) { if (nodes.ContainsKey(co)) { nodes[co].AddNeighbour(n); n.AddNeighbour(nodes[co]); } } nodes.Add(c, n); }
void GenerateX(int x) { for (int i = minZ; i <= maxZ; i++) { for (int j = minY; j <= maxY; j++) { Cord3D cord = new Cord3D(x, j, i); Node n = new Node(false); this.AddNode(cord, n); } } }
void GenerateY(int y) { for (int i = minX; i <= maxX; i++) { for (int j = minZ; j <= maxZ; j++) { Cord3D cord = new Cord3D(i, y, j); Node n = new Node(false); this.AddNode(cord, n); } } }
void GenerateZ(int z) { for (int i = minX; i <= maxX; i++) { for (int j = minY; j <= maxY; j++) { Cord3D cord = new Cord3D(i, j, z); Node n = new Node(false); this.AddNode(cord, n); } } }
public List <Cord4D> GetNeighbourCords() { List <Cord3D> temp = new Cord3D(x, y, z).GetNeighbourCords(); List <Cord4D> answer = new List <Cord4D>(); foreach (Cord3D c in temp) { answer.Add(new Cord4D(c.x, c.y, c.z, w - 1)); answer.Add(new Cord4D(c.x, c.y, c.z, w)); answer.Add(new Cord4D(c.x, c.y, c.z, w + 1)); } answer.Add(new Cord4D(x, y, z, w - 1)); answer.Add(new Cord4D(x, y, z, w + 1)); return(answer); }
public List <Cord3D> GetNeighbourCords() { Cord3D[] cords = new Cord3D[27]; for (int i = 0; i < 27; i++) { int a, b, c; a = x - ((i % 3) - 1); if ((i % 9) / 3 >= 2) { b = y + 1; } else if ((i % 9) / 3 >= 1) { b = y; } else { b = y - 1; } if (i / 18 >= 1) { c = z + 1; } else if (i / 9 >= 1) { c = z; } else { c = z - 1; } cords[i] = new Cord3D(a, b, c); } List <Cord3D> answer = new List <Cord3D>(cords); answer.RemoveAt(13); return(answer); }