private HashSet <Coord4> ExecuteTurn(HashSet <Coord4> coords) { var nextSet = new HashSet <Coord4>(); for (var w = minW - 1; w <= maxW + 1; w++) { for (var z = minZ - 1; z <= maxZ + 1; z++) { for (var y = minY - 1; y <= maxY + 1; y++) { for (var x = minX - 1; x <= maxX + 1; x++) { var coord = new Coord4(x, y, z, w); var neighbours = CountNeighbors(coords, coord); var isAlive = coords.Contains(coord); if ( (isAlive && (neighbours == 2 || neighbours == 3)) || // stays alive (!isAlive && neighbours == 3) ) { nextSet.Add(coord); minX = Math.Min(minX, x); minY = Math.Min(minY, y); minZ = Math.Min(minZ, z); minW = Math.Min(minW, w); maxX = Math.Max(maxX, x); maxY = Math.Max(maxY, y); maxZ = Math.Max(maxZ, z); maxW = Math.Max(maxW, w); } } } } } return(nextSet); }
private int CountNeighbors(HashSet <Coord4> coords, Coord4 coord) { var neighbors = 0; for (var w = coord.W - 1; w <= coord.W + 1; w++) { for (var z = coord.Z - 1; z <= coord.Z + 1; z++) { for (var y = coord.Y - 1; y <= coord.Y + 1; y++) { for (var x = coord.X - 1; x <= coord.X + 1; x++) { var neighbor = new Coord4(x, y, z, w); if (neighbor != coord && coords.Contains(neighbor)) { neighbors++; } } } } } return(neighbors); }
public void UpdateObjectPosition(ulong guid, Coord4 coord4, uint time) { Core.UpdateObjectPosition(guid, coord4.X, coord4.Y, coord4.Z, coord4.O, time, OpcodeName); }