public SimplexNoise(SimplexNoise other) { octaves = other.octaves; persistence = other.persistence; scale = other.scale; octaveScale = other.octaveScale; perm = other.perm; }
public World Initialize(bool loadWorld = false) { simplex = new SimplexNoise(GameManager.gameSeed); octaves = Random.Range(4, 4); multiplier = Random.Range(10, 10); amplitude = Random.Range(0.6f, 1f); lacunarity = Random.Range(0.7f, .9f); dAmplitude = Random.Range(0.5f, .1f); if (loadWorld) { activeWorld = LoadWorld(); } else { activeWorld = new World(); activeWorld.PrepForCache(worldScale, worldSubdivisions); } //Seed the world heights SetHeights(); //CreateOcean(); currentWorldObject = new GameObject("World"); currentWorldTrans = currentWorldObject.transform; //currentWorld = new World(WorldSize.Small, WorldType.Verdant, Season.Spring, AxisTilt.Slight); worldRenderer = GetComponent<WorldRenderer>(); //changed this to run RenderPlates instead of RenderWorld foreach (GameObject g in worldRenderer.RenderPlates(activeWorld, regularTileSet)) { g.transform.parent =currentWorldTrans; } //layermask = 1 << 8; // Layer 8 is set up as "Chunk" in the Tags & Layers manager labelDirections = true; //DrawHexIndices(); return activeWorld; }
public PolySphere(Vector3 o, float s, int d) { origin = o; scale = s; subdivisions = d; //For seeding dual centers simplex = new SimplexNoise(GameManager.gameSeed); octaves = Random.Range(1, 10); multiplier = Random.Range(9, 10); amplitude = Random.Range(0.3f, 1.2f); lacunarity = Random.Range(0.7f, .9f); dAmplitude = Random.Range(0.5f, .1f); icoCoords = new List<Vector3>(); icosahedronTris = Icosahedron(scale); SubdivideAndDuals(); //Builds SphereTiles TectonicPlates(); //Populates plates and creates stress forces between them. CacheHexes(); //Converts to HexTiles for serialization }
public void Start() { Noise = new SimplexNoise(); Noise.Initialize(); Root = new QuadTreeNode(this, null, Vector2.zero, Helper.ViewDistance, 4, 0); }
public void AddArea(XPoint2 pos, int size, float coherence, Func <XPoint2, bool> validityCheck) { int origSize = size; List <XPoint2> stack = new List <XPoint2>(); stack.Add(pos); int at = 0; int loopAt = stack.Count; for (int x = 0; x < Map.GetLength(0); ++x) { for (int y = 0; y < Map.GetLength(1); ++y) { Map[x, y].Weight = float.MinValue; } } Debug.Assert(pos.X >= 0 && pos.Y >= 0 && pos.X < Map.GetLength(0) && pos.Y < Map.GetLength(1), "Out of bounds"); Map[pos.X, pos.Y] = new Node() { Weight = -1 }; List <XPoint2> tmp = new List <XPoint2>(); activeArea = new XRectangle(pos.X, pos.Y, 1, 1); while (size > 0) { float maxV = float.MaxValue; for (int i = 0; i < stack.Count; ++i) { var p = stack[i]; var node = Map[p.X, p.Y]; Debug.Assert(node.Weight < 0, "Weight > 0 means the tile is already accepted!"); float weight = -node.Weight + (1 + node.Extra); if (weight < maxV) { maxV = weight; at = i; } } var pnt = stack[at]; { --size; stack.RemoveAt(at--); --loopAt; float val = Map[pnt.X, pnt.Y].Weight; Debug.Assert(val < 0, "Tile must have a negative weight to start with!"); Map[pnt.X, pnt.Y].Weight = 1; activeArea = activeArea.ExpandToInclude(pnt); const float NoiseScale = 100; tmp.Clear(); for (int p = 0; p < propogOffs.Length; ++p) { XPoint2 pnt2 = pnt + propogOffs[p]; if (pnt2.X >= 0 && pnt2.Y >= 0 && pnt2.X < Map.GetLength(0) && pnt2.Y < Map.GetLength(1)) { if (!validityCheck(pnt2)) { continue; } if (Map[pnt2.X, pnt2.Y].Weight > 0) { continue; } tmp.Add(pnt2); } } for (int t = 0; t < tmp.Count; ++t) { var pnt2 = tmp[t]; XPoint2 delta = pnt2 - pnt; float noise = (SimplexNoise.simplex_noise_3octaves(pnt2.X / NoiseScale, (delta.X + delta.Y * 2) * 5, pnt2.Y / NoiseScale) / 2 - 0.5f); float tVal = val - (float)Math.Sqrt(delta.X * delta.X + delta.Y * delta.Y); //tVal *= 1 + (noise - 0.5f) * (1 - coherence) / 0.3f; Map[pnt2.X, pnt2.Y].Weight = Math.Max(Map[pnt2.X, pnt2.Y].Weight, tVal); Map[pnt2.X, pnt2.Y].Extra = Math.Max( Map[pnt2.X, pnt2.Y].Extra, (noise - 0.0f) * (1 - coherence) / 0.5f * 50//origSize / 46 ); if (!stack.Contains(pnt2)) { stack.Add(pnt2); } } } if (stack.Count == 0) { break; } } }
public override double GetTemperature(int seed2, int seed3, double x, double y) { return(SimplexNoise.Generate((double)seed2 + (x / TemperatureMapSize), (double)seed3 + (y / TemperatureMapSize)) * 100f); }
public TestGenerator(VoxelWorld world, SimplexNoise noise) : base(world, noise) { proto = GetBlockData("proto"); proto_obj = GetBlockData("proto_obj"); }
public static double noise(double x, double y, double z) { return(SimplexNoise.Noise(x, y, y)); }
public static JsonArray Pack(SimplexNoise n) { return(new JsonArray(n.octaves, n.persistence, n.scale, n.octaveScale, n.noiseOffset.x, n.noiseOffset.y, n.noiseOffset.z)); }
public Generator(VoxelWorld world, SimplexNoise noise) { this.world = world; this.noise = noise; }
public float GetValue(SimplexNoise n, float x, float y, float z) => (n.Evaluate(x * frequency, y * frequency, z * frequency) * amplitude * 2 - amplitude) * weight;
void Update4D() { SimplexNoise noise = new SimplexNoise(seed); var prng = new System.Random(seed); float[] noiseMap = new float[res * res]; float maxVal = float.MinValue; float minVal = float.MaxValue; var offsets = new Vector4[layers]; for (int i = 0; i < layers; i++) { offsets[i] = new Vector4((float)prng.NextDouble() * 2 - 1, (float)prng.NextDouble() * 2 - 1, (float)prng.NextDouble() * 2 - 1, (float)prng.NextDouble() * 2 - 1) * 1000; } // circumference should = 1 (length of cylinder) // 2*pi*r = 1 therefore r = 1/(2pi) float radius = 1 / (2 * Mathf.PI); for (int x = 0; x < res; x++) { float px = x / (res - 1f); float angleZW = px * Mathf.PI * 2; float circleZ = Mathf.Cos(angleZW) * radius + offset.x; float circleW = Mathf.Sin(angleZW) * radius + offset.y; for (int y = 0; y < res; y++) { float py = y / (res - 1f); float angle = py * Mathf.PI * 2; float circleX = Mathf.Cos(angle) * radius; float circleY = Mathf.Sin(angle) * radius; float amplitude = 1; float frequency = scale; float noiseVal = 0; for (int i = 0; i < layers; i++) { Vector4 p = new Vector4(circleX, circleY, circleZ, circleW) * frequency + offsets[i]; noiseVal += (float)noise.Evaluate(p.x, p.y, p.z, p.w) * amplitude; amplitude *= persistence; frequency *= lacunarity; } noiseMap[x * res + y] = noiseVal; maxVal = Mathf.Max(maxVal, noiseVal); minVal = Mathf.Min(minVal, noiseVal); } } if (texture == null || texture.width != res) { texture = new Texture2D(res, res); } texture.wrapMode = TextureWrapMode.Repeat; var cols = new Color[noiseMap.Length]; for (int i = 0; i < cols.Length; i++) { float v = Mathf.InverseLerp(minVal, maxVal, noiseMap[i]); cols[i] = new Color(v, v, v); } texture.SetPixels(cols); texture.Apply(); GetComponent <MeshRenderer> ().sharedMaterial.mainTexture = texture; }
public static float _Noise(float gain, float x, float y, float t, float globalGain, float globalExpo) { var v = (globalGain * gain) * (float)SimplexNoise.Noise(x, y, t); return(v); }
public float nestHealthThreshold = 0; // How much health the queen needs to feel comfortable building a nest block #endregion Preset Genes #endregion Fields #region Initialization /// <summary> /// Awake is called before any start method is called. /// </summary> void Awake() { File.WriteAllText("CodyAntymologyResults.txt", string.Empty); // Clear the record file // Generate new random number generator RNG = new System.Random(ConfigurationManager.Instance.Seed); // Generate new simplex noise generator SimplexNoise = new SimplexNoise(ConfigurationManager.Instance.Seed); // Initialize a new 3D array of blocks with size of the number of chunks times the size of each chunk Blocks = new AbstractBlock[ ConfigurationManager.Instance.World_Diameter * ConfigurationManager.Instance.Chunk_Diameter, ConfigurationManager.Instance.World_Height *ConfigurationManager.Instance.Chunk_Diameter, ConfigurationManager.Instance.World_Diameter *ConfigurationManager.Instance.Chunk_Diameter]; // Initialize a new 3D array of chunks with size of the number of chunks Chunks = new Chunk[ ConfigurationManager.Instance.World_Diameter, ConfigurationManager.Instance.World_Height, ConfigurationManager.Instance.World_Diameter]; if (!usingPresets) { // Initial genome pool firstBestGenerationGenome = GenerateNewGenome(); secondBestGenerationGenome = GenerateNewGenome(); bestGenomeEver = new float[7] { 1, 1, 1, 1, 1, 1, 1 }; } else { genome[0] = foodPheromoneAmount; genome[1] = acidPheromoneAmount; genome[2] = queenPheromoneAmount; genome[3] = foodPheromoneDetectionLimit; genome[4] = nestPheromoneDetectionLimit; genome[5] = maximumHealthToTransfer; genome[6] = nestHealthThreshold; firstBestGenerationGenome = genome; secondBestGenerationGenome = genome; bestGenomeEver = genome; } firstBestNestBlocks = 0; secondBestNestBlocks = 0; bestGenerationNestBlocks = 0; bestGeneration = 0; // Create the world GenerateData(); GenerateChunks(); Camera.main.transform.position = new Vector3(0 / 2, Blocks.GetLength(1), 0); Camera.main.transform.LookAt(new Vector3(Blocks.GetLength(0), 0, Blocks.GetLength(2))); // Store the world InitialBlocks = new AbstractBlock[Blocks.GetLength(0), Blocks.GetLength(1), Blocks.GetLength(2)]; CopyBlocks(); }
public static SPTerrainRect InstantiateSPTerrainRect(IntVector4 pos, int minCount, int maxCount, Transform parent, SimplexNoise noise) { GameObject obj = new GameObject(pos.x + " , " + pos.z); obj.transform.parent = parent; obj.transform.position = pos.ToVector3(); SPTerrainRect rect = obj.AddComponent <SPTerrainRect>(); rect.Init(pos, minCount, maxCount, noise); return(rect); }
public static void Build(RockThreadReturnData returnData) { RockData data = returnData.RockData; MeshDraft MD; switch (data.RockBasePrimitiveShape) { case RockData.BasePrimitiveShapes.Dodecahedron: MD = MeshDraft.Dodecahedron(0.5f); break; case RockData.BasePrimitiveShapes.Icosahedron: MD = MeshDraft.Icosahedron(0.5f, false); break; case RockData.BasePrimitiveShapes.Prism: MD = MeshDraft.Prism(0.5f, data.Segments, 1f, false); break; case RockData.BasePrimitiveShapes.Pyramid: MD = MeshDraft.Pyramid(0.5f, data.Segments, 1f, false); break; default: MD = MeshDraft.Sphere(0.5f, data.Segments, data.Segments, false); break; } ; MeshObjectData rock = new MeshObjectData(); rock.vertices = MD.vertices.ToArray(); rock.triangles = MD.triangles.ToArray(); rock.tangents = MD.tangents.ToArray(); rock.AutoWeldMesh(0.0001f, 0.4f); Vector3[] verts = rock.vertices; INoise noise = new SimplexNoise(data.RockSeed, 0.3f, 0.2f); Rand r = new Rand(data.RockSeed); for (int i = 0; i < verts.Length; i++) { float currentNoise = NoiseGen(noise, 3, verts[i].x / 0.5f, verts[i].y / 0.5f, verts[i].z / 0.5f); //currentNoise*=2; Vector3 norm = verts[i].normalized; verts[i].x += currentNoise * norm.x; verts[i].y += currentNoise * norm.y; verts[i].z += currentNoise * norm.z; verts[i].x *= 3; verts[i].y *= 1.2f; verts[i].z *= 1.5f; } rock.vertices = verts; rock.flatShade(); Color[] vertexColor = new Color[rock.vertices.Length]; for (int i = 0; i < rock.vertices.Length; i++) { vertexColor[i] = data.RockGradientColor.Color.Evaluate(1 - rock.vertices[i].y); } rock.colors = vertexColor; returnData.RockBuildData = rock; returnData.ManagerCallBack(returnData); }
/// <summary> /// Generates a Simplex Noise based on the settings and displays it as a bitmap in the picture box. /// </summary> private void GenerateNoise() { // Setup defaults for settings for the simplex noise engine int seed = new Random().Next(1, int.MaxValue); if (!string.IsNullOrEmpty(txtSeed.Text)) { seed = int.Parse(txtSeed.Text); } double persistence = 0.7; if (!string.IsNullOrEmpty(txtPersistence.Text)) { persistence = double.Parse(txtPersistence.Text); } int xResolution = pbNoise.Size.Width; if (!string.IsNullOrEmpty(txtXResolution.Text)) { xResolution = int.Parse(txtXResolution.Text); } int yResolution = pbNoise.Size.Height; if (!string.IsNullOrEmpty(txtYResolution.Text)) { yResolution = int.Parse(txtYResolution.Text); } int largestFeature = 850; if (!string.IsNullOrEmpty(txtLargestFeature.Text)) { largestFeature = int.Parse(txtLargestFeature.Text); if (largestFeature < 1) { largestFeature = 1; } } // Display the seed in case it was generated txtGeneratedSeed.Text = seed.ToString(); // Initialize the simplex noise engine var noise = new SimplexNoise(largestFeature, persistence, seed); double xStart = 0; double xEnd = 500; double yStart = 0; double yEnd = 500; var result = new double[xResolution, yResolution]; for (int i = 0; i < xResolution; i++) { for (int j = 0; j < yResolution; j++) { var x = (int)(xStart + i * ((xEnd - xStart) / xResolution)); var y = (int)(yStart + j * ((yEnd - yStart) / yResolution)); result[i, j] = 0.5 * (1 + noise.GetNoise(x, y)); } } // Generate the results in a bitmap and display in the picture box pbNoise.Image = GenerateBitmap(result, xResolution, yResolution); }
private int GetHeight(int x, int z) { var noise = Math.Abs(SimplexNoise.Evaluate(x / 256f, z / 256f)); return(1 + (int)Math.Ceiling(noise * Height)); }
public void Initialize() { precipitationNoise = SimplexNoise.FromDefaultOctaves(4, 0.02 / 3, 0.95, api.World.Seed - 18971121); precipitationNoiseSub = SimplexNoise.FromDefaultOctaves(3, 0.004 / 3, 0.95, api.World.Seed - 1717121); }
/// <summary> /// Starts plan generation process /// </summary> public void Generate() { var datapoints = new List <Vector>(Parameters.PolygonsCount); var r = new Random(Parameters.GridSeed); for (int i = 0; i < Parameters.PolygonsCount; i++) { datapoints.Add(new Vector(r.Next(0, Parameters.MapSize.X), r.Next(0, Parameters.MapSize.Y))); } var graph = Fortune.ComputeVoronoiGraph(datapoints); for (int i = 0; i < Parameters.RelaxCount; i++) { Relax(graph, datapoints); graph = Fortune.ComputeVoronoiGraph(datapoints); } FillMap(graph); { // adding elevation data var elevationNoise = new SimplexNoise(new Random(Parameters.ElevationSeed)); elevationNoise.SetParameters(0.0008, SimplexNoise.InflectionMode.NoInflections, SimplexNoise.ResultScale.ZeroToOne); foreach (var poly in this) { var noiseVal = elevationNoise.GetNoise2DValue(poly.Center.X, poly.Center.Y, 4, 0.8); var col = 255 / noiseVal.MaxValue * noiseVal.Value; poly.Elevation = (int)col; } //// elevate each corner //if (!Parameters.CenterElevation) // ElevateCorners(); } if (Parameters.CenterElevation) { var poly = GetAtPoint(new Point(Parameters.MapSize.X / 2, Parameters.MapSize.Y / 2)); poly.Elevation = 200; StartPropagation(poly, 15); } // making island { //r = new Random((int)voronoiSeedNumeric.Value); var borderElevation = 80; var step = 20; for (int x = 0; x < Parameters.MapSize.X; x += 5) { var poly = GetAtPoint(new Point(x, 0)); poly.Elevation = borderElevation;// r.Next(0, 100); StartPropagation(poly, step); poly = GetAtPoint(new Point(x, Parameters.MapSize.Y)); poly.Elevation = borderElevation;// r.Next(0, 100); StartPropagation(poly, step); } for (int y = 0; y < Parameters.MapSize.Y; y += 5) { var poly = GetAtPoint(new Point(0, y)); poly.Elevation = borderElevation;// r.Next(0, 100); StartPropagation(poly, step); poly = GetAtPoint(new Point(Parameters.MapSize.X, y)); poly.Elevation = borderElevation;// r.Next(0, 100); StartPropagation(poly, step); } } ElevateCorners(); #region Moisturizing { var noise = new SimplexNoise(new Random(Parameters.ElevationSeed)); noise.SetParameters(0.0008d, SimplexNoise.InflectionMode.NoInflections, SimplexNoise.ResultScale.ZeroToOne); foreach (var poly in this) { var noiseVal = noise.GetNoise2DValue(poly.Center.X, poly.Center.Y, 2, 0.8); var col = 100 / noiseVal.MaxValue * noiseVal.Value; poly.Moisture = (int)col; foreach (var corner in poly.Corners) { noiseVal = noise.GetNoise2DValue(corner.Point.X, corner.Point.Y, 2, 0.8); col = 2 / noiseVal.MaxValue * noiseVal.Value; corner.WaterFlow = (int)col; } } // fix heights foreach (var poly in this) { foreach (var neighbor in poly.Neighbors) { if (poly.Elevation == neighbor.Elevation) { neighbor.Elevation = (int)neighbor.Neighbors.Average(n => n.Elevation); } } } // calculate rivers _corners1 = new HashSet <Corner>(); // get unique corners foreach (var poly in this) { foreach (var corner in poly.Corners) { if (!_corners1.Contains(corner) && corner.Polygons.Find(p => p.Elevation <= 127) == null) { _corners1.Add(corner); } } } var list = new List <Corner>(_corners1); list.Sort(new CornerHeightComparer()); // propagate flow foreach (var corner in list) { // find lowest edge Edge lowestEdge = corner.Edges[0]; int height = lowestEdge.GetOpposite(corner).Elevation; for (int i = 0; i < corner.Edges.Count; i++) { var tmp = corner.Edges[i].GetOpposite(corner).Elevation; if (tmp < height) { height = tmp; lowestEdge = corner.Edges[i]; } } lowestEdge.WaterFlow += corner.WaterFlow; lowestEdge.GetOpposite(corner).WaterFlow += corner.WaterFlow; } // remove rivers that not going to oceans _waterCorners = new List <Corner>(); foreach (var poly in this) { foreach (var corner in poly.Corners) { int solid = corner.Polygons.Count(p => p.Elevation > 127); if (solid == 2) { _waterCorners.Add(corner); } } } // collect all correct edges _rivers.Clear(); foreach (var waterCorner in _waterCorners) { var root = new RiverBranch(); CollectRiver(waterCorner, root); if (!root.Final) { _riverRoots.Add(root); } } // fix river flows // stage 1: remove all flows foreach (var riverBranch in _riverRoots) { EnumerateTree(riverBranch, b => { if (b.Edge != null) { b.Edge.WaterFlow = 0; } }); } // stage 2: reflow it foreach (var riverBranch in _riverRoots) { FillRiver(riverBranch); } // remove all non-river foreach (var poly in this) { foreach (var edge in poly.Edges) { if (edge.WaterFlow > 0 && !_rivers.Contains(edge)) { edge.WaterFlow = 0; } } } // update moisture for polygons foreach (var poly in this) { if (poly.Elevation > 127) { poly.Moisture = poly.Neighbors.Sum(p => { var v = p.Neighbors.Sum(n => n.Edges.Sum(ed => ed.WaterFlow > 0 ? 1 : 0)); v = v + p.Neighbors.Sum(n => n.Elevation < 127 && !n.Ocean ? 3 : 0); return(p.Edges.Sum(ed => ed.WaterFlow > 0 ? 1 : 0) + v); }); } } } #endregion // detect ocean { SetOcean(GetAtPoint(new Point(0, 0))); SetOcean(GetAtPoint(new Point(Parameters.MapSize.X, 0))); SetOcean(GetAtPoint(new Point(0, Parameters.MapSize.Y))); SetOcean(GetAtPoint(new Point(Parameters.MapSize.X, Parameters.MapSize.Y))); } // set biomes { foreach (var poly in this) { if (poly.Elevation > 127) { poly.Biome = _biome.GetBiomeWith(poly.Elevation, poly.Moisture > _biome.Moisture.Maximum ? _biome.Moisture.Maximum : poly.Moisture); } } } //find coastline foreach (var polygon in this) { foreach (var edge in polygon.Edges) { Polygon poly; Polygon poly2; if (((poly = edge.Polygons.Find(p => p.Elevation > 127)) != null) && ((poly2 = edge.Polygons.Find((p => p.Elevation <= 127))) != null)) { poly.Coast = true; poly2.Coast = true; edge.Coast = true; } } } }
private static int GetNoise(int x, int y, int z, float scale, int max) { return(Mathf.FloorToInt((SimplexNoise.Generate(x * scale, y * scale, z * scale) + 1f) * (max / 2f))); }
public float CalculateMountainRangeFactor(float x, float z) { return(1f - MathUtils.Abs(2f * SimplexNoise.OctavedNoise(x, z, 0.0014f, 3, 1.91f, 0.75f) - 1f)); }
public static double noise(double x, double y, double z, double w) { return(SimplexNoise.Noise(x, y, z, w)); }
private void _GenerateNoiseOctaves() { Color[] pixelsForOctaves = new Color[width * height * 4]; Vector3 sunDir = sunDirection.normalized; Vector2[] displacements = new Vector2[3]; displacements[0] = new Vector2(Mathf.Floor(sunDir.x * 10.0f), Mathf.Floor(sunDir.z * 10.0f)); displacements[1] = displacements[0] * 2.0f; displacements[2] = displacements[0] * 3.0f; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { float scale = 2.0f; float noise = 0.0f; float[] noiseDisplaced = new float[3]; for (int o = 0; o < 4; o++) { // The real noise noise = SimplexNoise.SeamlessNoise((float)j / width, (float)i / height, scale, scale, 20.0f); noise = noise * 0.5f + 0.5f; for (int s = 0; s < 3; s++) { float yDisplaced = ((float)i + displacements[s].y) / height; float xDisplaced = ((float)j + displacements[s].x) / width; while (xDisplaced > 1.0f) { xDisplaced = xDisplaced - 1.0f; } while (yDisplaced > 1.0f) { yDisplaced = yDisplaced - 1.0f; } while (xDisplaced < 0.0f) { xDisplaced = xDisplaced + 1.0f; } while (yDisplaced < 0.0f) { yDisplaced = yDisplaced + 1.0f; } noiseDisplaced[s] = SimplexNoise.SeamlessNoise(xDisplaced, yDisplaced, scale, scale, 20.0f); noiseDisplaced[s] = noiseDisplaced[s] * 0.5f + 0.5f; } pixelsForOctaves[width * height * o + i * width + j] = new Color(noise, noiseDisplaced[0], noiseDisplaced[1], noiseDisplaced[2]); scale *= 2.0f; } } } List <Color> pixels = new List <Color>(pixelsForOctaves); for (int o = 0; o < 4; o++) { Texture2D octave = new Texture2D(width, height, TextureFormat.ARGB32, false, true); octave.filterMode = FilterMode.Bilinear; octave.wrapMode = TextureWrapMode.Repeat; octave.SetPixels(pixels.GetRange(width * height * o, width * height).ToArray()); octave.Apply(); byte[] bytes = octave.EncodeToPNG(); System.IO.File.WriteAllBytes(Application.dataPath + "/2DDynamicClouds/Textures/Octave" + o.ToString() + ".png", bytes); } }
public MapLayerCustomPerlin(long seed, double[] amplitudes, double[] frequencies, double[] thresholds) : base(seed) { noisegen = new SimplexNoise(amplitudes, frequencies, seed + 12321); this.thresholds = thresholds; }
public void GenerateTexture(int xSize, int ySize, ref List <Color> colors, ref List <Color> normals, int r) {/* * brickMesh.GetComponent<MeshRenderer>().material = brickMat; * * Texture2D brickTexture = new Texture2D(xSize, ySize, TextureFormat.ARGB32, false); * Texture2D brickNormals = new Texture2D(xSize, ySize, TextureFormat.ARGB32, false);*/ holes = new float[xSize, ySize]; pixels = new float[xSize, ySize]; cracks = new float[xSize, ySize]; Noise pn = new SimplexNoise(seed, .2f); for (int y = 0; y < ySize; y++) { for (int x = 0; x < xSize; x++) { float zSplotch = pn.Sample2D(x * xSplotching + perlinOffset, y * ySplotching + perlinOffset); zSplotch = (zSplotch + 3.5f) / 4.5f; float zHole = Mathf.PerlinNoise(x * xHoling - perlinOffset, y * yHoling - perlinOffset); if (zHole <= holeCutoff) { zHole *= 1f / holeCutoff; } else { zHole = 1; } holes[x, y] = zHole; cracks[x, y] = 1; //pixels[x, y] = zSplotch * zHole; pixels[x, y] = zSplotch; // * zHole; //uncomment for no normals } } Random.InitState(r); if (Random.value <= crackChance) { float xCase = Random.value; float yCase = Random.value; Vector2 position = Vector2.zero; Vector2 direction = Vector2.zero; if (xCase < .5f) { if (yCase < .5f) { position = new Vector2(0, Random.value * (ySize - 1)); direction = new Vector2(1, 0); } else { position = new Vector2(xSize - 1, Random.value * (ySize - 1)); direction = new Vector2(-1, 0); } } else { if (yCase < .5f) { position = new Vector2(Random.value * (xSize - 1), 0); direction = new Vector2(0, 1); } else { position = new Vector2(Random.value * (xSize - 1), ySize - 1); direction = new Vector2(0, -1); } } cracks[Mathf.RoundToInt(position.x), Mathf.RoundToInt(position.y)] = 0; for (int y = -crackWidth; y <= crackWidth; y++) { for (int x = -crackWidth; x <= crackWidth; x++) { if (Mathf.RoundToInt(position.x) + x < 0 || Mathf.RoundToInt(position.y) + y < 0 || Mathf.RoundToInt(position.y) + y > ySize - 1 || Mathf.RoundToInt(position.x) + x > xSize - 1 || (x == 0 && y == 0)) { continue; } cracks[Mathf.RoundToInt(position.x) + x, Mathf.RoundToInt(position.y) + y] *= Mathf.Clamp01(Mathf.Abs(x) + Mathf.Abs(y) / (1f * crackWidth)); } } position += direction * crackIncrement; while (position.x >= 0 && position.y >= 0 && position.y <= ySize - 1 && position.x <= xSize - 1 && Random.value > crackStopChance) { cracks[Mathf.RoundToInt(position.x), Mathf.RoundToInt(position.y)] = 0; int i = 0; for (int y = -crackWidth; y <= crackWidth; y++) { for (int x = -crackWidth; x <= crackWidth; x++) { if (Mathf.RoundToInt(position.x) + x < 0 || Mathf.RoundToInt(position.y) + y < 0 || Mathf.RoundToInt(position.y) + y > ySize - 1 || Mathf.RoundToInt(position.x) + x > xSize - 1 || (x == 0 && y == 0)) { continue; } i++; cracks[Mathf.RoundToInt(position.x) + x, Mathf.RoundToInt(position.y) + y] *= Mathf.Clamp01((Mathf.Abs(x) + Mathf.Abs(y)) / (1f * crackWidth)); } } float xShift = 2 * (Random.value - .5f) * crackShift; float yShift = 2 * (Random.value - .5f) * crackShift; direction += new Vector2(xShift, yShift); direction.Normalize(); position += direction * crackIncrement; } } for (int y = 0; y < ySize; y++) { for (int x = 0; x < xSize; x++) { if (x == 0 || y == 0 || y == ySize - 1 || x == xSize - 1 || (holes[x, y] >= 0.9f && cracks[x, y] >= 0.9f)) { colors.Add(brickColor * pixels[x, y] * cracks[x, y]); normals.Add(new Color(.5f, .5f, 1f, 1)); continue; } if (cracks[x, y] >= 0.3f) { float dx = holes[x + 1, y] - holes[x - 1, y]; float dy = holes[x, y + 1] - holes[x, y - 1]; float div = Mathf.Sqrt(dx * dx + dy * dy + 1); float xn = -dx / div; float yn = -dy / div; float zn = 1 / div; normals.Add(new Color((xn + 1) / 2, (yn + 1) / 2, zn, 1)); //colors.Add(brickColor * pixels[x, y] * holes[x, y]); //uncomment for no normals colors.Add(brickColor * pixels[x, y]); } else { float dx = cracks[x + 1, y] - cracks[x - 1, y]; float dy = cracks[x, y + 1] - cracks[x, y - 1]; float div = Mathf.Sqrt(dx * dx + dy * dy + 1); float xn = -dx / div; float yn = -dy / div; float zn = 1 / div; normals.Add(new Color((xn + 1) / 2, (yn + 1) / 2, zn, 1)); //colors.Add(brickColor * pixels[x, y] * cracks[x, y]); //uncomment for no normals colors.Add(brickColor * pixels[x, y]); } } } /* * brickNormals.Apply(); * * brickMat.SetTexture("_MainTex", brickTexture); * brickMat.SetTexture("_BumpMap", brickNormals);*/ }
public override double GetDownfallRate(int seed3, int seed4, double x, double y) { return(SimplexNoise.Generate((double)seed3 + (x / DownfallMapSize), (double)seed4 + (y / DownfallMapSize))); }
private void GenerateNoise() { SetSeed(); NoiseBase noise = new SimplexNoise(seed); _map = noise.CreateSimpleMap(resolution, octaves, frequency, amplitude, seamless); }
void ReGen() { m_Grasses.Clear(); SimplexNoise noise = new SimplexNoise(); //Random.seed = Time.frameCount + Mathf.RoundToInt(Random.value*1000000); RaycastHit rch; for (int i = 0; i < m_GrassCount; i++) { Vector3 origin = new Vector3(Random.value, 1, Random.value) * m_GenAreaSize + m_StartCoord; // IntVector3 origin_i = new IntVector3(origin); // int hash = origin_i.GetHashCode(); // // if ( !m_map.ContainsKey(hash) ) // m_map.Add(hash, new List<GrassInstance>()); // if ( m_map[hash].Count > 1 ) // { // float p = Mathf.Pow(0.7f, (float)(m_map[hash].Count)); // if ( Random.value > p ) // continue; // } origin.y = 512f; if (Physics.Raycast(origin, Vector3.down, out rch, 1024, 1 << Pathea.Layer.VFVoxelTerrain)) { float nx = (float)(noise.Noise(rch.point.x / 32, rch.point.y / 32, rch.point.z / 32)) + 1; float ny = (float)(noise.Noise((rch.point.x + m_GenAreaSize) / 32, (rch.point.y + m_GenAreaSize) / 32, (rch.point.z + m_GenAreaSize) / 32)) + 1; float nz = (float)(noise.Noise(rch.point.y / 16, rch.point.z / 16, rch.point.x / 16)) + 1; nx = Mathf.Pow(nx, 15); ny = Mathf.Pow(ny, 15); nz = Mathf.Pow(nz, 15); float sum = nx + ny + nz; nx /= sum; ny /= sum; ny += nx; nz /= sum; nz += ny; GrassInstance gi = new GrassInstance(); gi.Position = rch.point; gi.Normal = rch.normal; gi.ColorF = m_GrassColor; float r = Random.value; if (r < nx) { gi.Prototype = m_ProtoType0; } else if (r < ny) { gi.Prototype = m_ProtoType1; } else if (r < nz) { gi.Prototype = m_ProtoType2; } m_Grasses.Add(gi); // m_map[hash].Add(gi); } } TrigrassMeshComputer.ComputeMesh(m_Grasses, 0, m_Mesh); m_Grasses.Clear(); }
private void GenerateTurbulentNoise() { SetSeed(); var noise = new SimplexNoise(seed); _map = noise.CreateTurbilenceMap(resolution, octaves, frequency, amplitude, seamless); }
void Update() { float[] offset = new float[] { 0.5f * Time.time, 0.25f * Time.time, 0.1f * Time.time }; int seed = (int)Mathf.Floor(2.0f * Time.time); float[] output1 = new float[m_gridExtent]; float[] output1Sqr = new float[m_gridExtent * m_gridExtent]; float[] output1Cub = new float[m_gridExtent * m_gridExtent * m_gridExtent]; float[,] output2 = new float[m_gridExtent, m_gridExtent]; float[,,] output3 = new float[m_gridExtent, m_gridExtent, m_gridExtent]; Vector2[] output1v2 = new Vector2[m_gridExtent]; Vector2[] output1v2Sqr = new Vector2[m_gridExtent * m_gridExtent]; Vector2[,] output2v2 = new Vector2[m_gridExtent, m_gridExtent]; Vector3[] output1v3 = new Vector3[m_gridExtent]; Vector3[] output1v3Sqr = new Vector3[m_gridExtent * m_gridExtent]; Vector3[] output1v3Cub = new Vector3[m_gridExtent * m_gridExtent * m_gridExtent]; Vector3[,] output2v3 = new Vector3[m_gridExtent, m_gridExtent]; Vector3[,,] output3v3 = new Vector3[m_gridExtent, m_gridExtent, m_gridExtent]; float[] scale = new float[] { 3.0f, 3.0f, 3.0f }; float[] period = new float[] { 0.15f, 0.15f, 0.15f }; Vector2[] input1v2 = new Vector2[m_gridExtent]; Vector2[] input1v2Sqr = new Vector2[m_gridExtent * m_gridExtent]; Vector3[] input1v3 = new Vector3[m_gridExtent]; Vector3[] input1v3Sqr = new Vector3[m_gridExtent * m_gridExtent]; Vector3[] input1v3Cub = new Vector3[m_gridExtent * m_gridExtent * m_gridExtent]; for (int z = 0; z < m_gridExtent; ++z) { for (int y = 0; y < m_gridExtent; ++y) { for (int x = 0; x < m_gridExtent; ++x) { int i = ((z * m_gridExtent) + y) * m_gridExtent + x; if (z == 0) { if (y == 0) { Vector3 p1 = new Vector3(x, y, z); input1v2[i].Set(p1.x, p1.y); input1v3[i] = p1; } Vector3 p2 = new Vector3(x, y, z); input1v2Sqr[i].Set(p2.x, p2.y); input1v3Sqr[i] = p2; } Vector3 p3 = new Vector3(x, y, z); input1v3Cub[i] = p3; } } } switch (m_noiseType) { case NoiseType.Classic1D: offset[1] = offset[2] = 0.0f; switch (m_mode) { case Mode.kGpuComputeGridSamples: ClassicNoise.Compute(output1, scale[0], offset[0], m_numOctaves, m_octaveOffsetFactor); Draw(output1); break; case Mode.kGpuComputeCustomSamples: ClassicNoise.Compute(input1v2, output1, scale, offset, m_numOctaves, m_octaveOffsetFactor); Draw(input1v2, output1); break; case Mode.kCpu: // TODO break; } break; case NoiseType.Classic2D: offset[2] = 0.0f; switch (m_mode) { case Mode.kGpuComputeGridSamples: ClassicNoise.Compute(output2, scale, offset, m_numOctaves, m_octaveOffsetFactor); Draw(output2); break; case Mode.kGpuComputeCustomSamples: ClassicNoise.Compute(input1v2Sqr, output1Sqr, scale, offset, m_numOctaves, m_octaveOffsetFactor); Draw(input1v2Sqr, output1Sqr); break; case Mode.kCpu: // TODO break; } break; case NoiseType.Classic3D: switch (m_mode) { case Mode.kGpuComputeGridSamples: ClassicNoise.Compute(output3, scale, offset, m_numOctaves, m_octaveOffsetFactor); Draw(output3); break; case Mode.kGpuComputeCustomSamples: ClassicNoise.Compute(input1v3Cub, output1Cub, scale, offset, m_numOctaves, m_octaveOffsetFactor); Draw(input1v3Cub, output1Cub); break; case Mode.kCpu: // TODO break; } break; case NoiseType.ClassicPeriodic1D: offset[1] = offset[2] = 0.0f; switch (m_mode) { case Mode.kGpuComputeGridSamples: ClassicNoisePeriodic.Compute(output1, scale[0], offset[0], period[0], m_numOctaves, m_octaveOffsetFactor); Draw(output1); break; case Mode.kGpuComputeCustomSamples: ClassicNoisePeriodic.Compute(input1v2, output1, scale, offset, period, m_numOctaves, m_octaveOffsetFactor); Draw(input1v2, output1); break; case Mode.kCpu: // TODO break; } break; case NoiseType.ClassicPeriodic2D: switch (m_mode) { case Mode.kGpuComputeGridSamples: ClassicNoisePeriodic.Compute(output2, scale, offset, period, m_numOctaves, m_octaveOffsetFactor); Draw(output2); break; case Mode.kGpuComputeCustomSamples: offset[2] = 0.0f; ClassicNoisePeriodic.Compute(input1v2Sqr, output1Sqr, scale, offset, period, m_numOctaves, m_octaveOffsetFactor); Draw(input1v2Sqr, output1Sqr); break; case Mode.kCpu: // TODO break; } break; case NoiseType.ClassicPeriodic3D: switch (m_mode) { case Mode.kGpuComputeGridSamples: ClassicNoisePeriodic.Compute(output3, scale, offset, period, m_numOctaves, m_octaveOffsetFactor); Draw(output3); break; case Mode.kGpuComputeCustomSamples: ClassicNoisePeriodic.Compute(input1v3Cub, output1Cub, scale, offset, period, m_numOctaves, m_octaveOffsetFactor); Draw(input1v3Cub, output1Cub); break; case Mode.kCpu: // TODO break; } break; case NoiseType.Random1D: offset[1] = offset[2] = 0.0f; switch (m_mode) { case Mode.kGpuComputeGridSamples: case Mode.kGpuComputeCustomSamples: // pointless RandomNoise.Compute(output1, seed); Draw(output1); break; case Mode.kCpu: for (int x = 0; x < output1.GetLength(0); ++x) { output1[x] = RandomNoise.Get(x, seed); } Draw(output1); break; } break; case NoiseType.Random2D: offset[2] = 0.0f; switch (m_mode) { case Mode.kGpuComputeGridSamples: case Mode.kGpuComputeCustomSamples: // pointless RandomNoise.Compute(output2, seed); Draw(output2); break; case Mode.kCpu: for (int y = 0; y < output2.GetLength(1); ++y) { for (int x = 0; x < output2.GetLength(0); ++x) { output2[y, x] = RandomNoise.Get(new Vector2(x, y), seed); } } Draw(output2); break; } break; case NoiseType.Random3D: switch (m_mode) { case Mode.kGpuComputeGridSamples: case Mode.kGpuComputeCustomSamples: // pointless RandomNoise.Compute(output3, seed); break; case Mode.kCpu: for (int z = 0; z < output3.GetLength(2); ++z) { for (int y = 0; y < output3.GetLength(1); ++y) { for (int x = 0; x < output3.GetLength(0); ++x) { output3[z, y, x] = RandomNoise.Get(new Vector3(x, y, z), seed); } } } break; } Draw(output3); break; case NoiseType.RandomVector1DVec2: offset[1] = offset[2] = 0.0f; RandomNoiseVector.Compute(output1v2, seed); Draw(output1v2); break; case NoiseType.RandomVector2DVec2: offset[2] = 0.0f; RandomNoiseVector.Compute(output2v2, seed); Draw(output2v2); break; case NoiseType.RandomVector1DVec3: offset[1] = offset[2] = 0.0f; RandomNoiseVector.Compute(output1v3, seed); Draw(output1v3); break; case NoiseType.RandomVector2DVec3: offset[2] = 0.0f; RandomNoiseVector.Compute(output2v3, seed); Draw(output2v3); break; case NoiseType.RandomVector3DVec3: RandomNoiseVector.Compute(output3v3, seed); Draw(output3v3); break; case NoiseType.Simplex1D: offset[1] = offset[2] = 0.0f; switch (m_mode) { case Mode.kGpuComputeGridSamples: SimplexNoise.Compute(output1, scale[0], offset[0], m_numOctaves, m_octaveOffsetFactor); Draw(output1); break; case Mode.kGpuComputeCustomSamples: SimplexNoise.Compute(input1v2, output1, scale, offset, m_numOctaves, m_octaveOffsetFactor); Draw(input1v2, output1); break; case Mode.kCpu: // TODO break; } break; case NoiseType.Simplex2D: offset[2] = 0.0f; switch (m_mode) { case Mode.kGpuComputeGridSamples: SimplexNoise.Compute(output2, scale, offset, m_numOctaves, m_octaveOffsetFactor); Draw(output2); break; case Mode.kGpuComputeCustomSamples: SimplexNoise.Compute(input1v2Sqr, output1Sqr, scale, offset, m_numOctaves, m_octaveOffsetFactor); Draw(input1v2Sqr, output1Sqr); break; case Mode.kCpu: // TODO break; } break; case NoiseType.Simplex3D: switch (m_mode) { case Mode.kGpuComputeGridSamples: SimplexNoise.Compute(output3, scale, offset, m_numOctaves, m_octaveOffsetFactor); Draw(output3); break; case Mode.kGpuComputeCustomSamples: SimplexNoise.Compute(input1v3Cub, output1Cub, scale, offset, m_numOctaves, m_octaveOffsetFactor); Draw(input1v3Cub, output1Cub); break; case Mode.kCpu: // TODO break; } break; case NoiseType.SimplexGradient1DVec2: offset[1] = offset[2] = 0.0f; switch (m_mode) { case Mode.kGpuComputeGridSamples: SimplexNoiseGradient.Compute(output1v2, scale[0], offset[0], m_numOctaves, m_octaveOffsetFactor); Draw(output1v2); break; case Mode.kGpuComputeCustomSamples: SimplexNoiseGradient.Compute(input1v2, output1v2, scale, offset, m_numOctaves, m_octaveOffsetFactor); Draw(input1v2, output1v2); break; case Mode.kCpu: // TODO break; } break; case NoiseType.SimplexGradient2DVec2: offset[2] = 0.0f; switch (m_mode) { case Mode.kGpuComputeGridSamples: SimplexNoiseGradient.Compute(output2v2, scale, offset, m_numOctaves, m_octaveOffsetFactor); Draw(output2v2); break; case Mode.kGpuComputeCustomSamples: SimplexNoiseGradient.Compute(input1v2Sqr, output1v2Sqr, scale, offset, m_numOctaves, m_octaveOffsetFactor); Draw(input1v2Sqr, output1v2Sqr); break; case Mode.kCpu: // TODO break; } break; case NoiseType.SimplexGradient1DVec3: offset[1] = offset[2] = 0.0f; switch (m_mode) { case Mode.kGpuComputeGridSamples: SimplexNoiseGradient.Compute(output1v3, scale[0], offset[0], m_numOctaves, m_octaveOffsetFactor); Draw(output1v3); break; case Mode.kGpuComputeCustomSamples: SimplexNoiseGradient.Compute(input1v3, output1v3, scale, offset, m_numOctaves, m_octaveOffsetFactor); Draw(input1v3, output1v3); break; case Mode.kCpu: // TODO break; } break; case NoiseType.SimplexGradient2DVec3: offset[2] = 0.0f; switch (m_mode) { case Mode.kGpuComputeGridSamples: SimplexNoiseGradient.Compute(output2v3, scale, offset, m_numOctaves, m_octaveOffsetFactor); Draw(output2v3); break; case Mode.kGpuComputeCustomSamples: SimplexNoiseGradient.Compute(input1v3Sqr, output1v3Sqr, scale, offset, m_numOctaves, m_octaveOffsetFactor); Draw(input1v3Sqr, output1v3Sqr); break; case Mode.kCpu: // TODO break; } break; case NoiseType.SimplexGradient3DVec3: switch (m_mode) { case Mode.kGpuComputeGridSamples: SimplexNoiseGradient.Compute(output3v3, scale, offset, m_numOctaves, m_octaveOffsetFactor); Draw(output3v3); break; case Mode.kGpuComputeCustomSamples: SimplexNoiseGradient.Compute(input1v3Cub, output1v3Cub, scale, offset, m_numOctaves, m_octaveOffsetFactor); Draw(input1v3Cub, output1v3Cub); break; case Mode.kCpu: // TODO break; } break; } }
protected virtual double GetRockHeight(int blockX, int blockZ) { return(SimplexNoise.noise(blockX * 0.02f, blockZ * 0.02f) * 100); }
private void GenerateSinusNoise() { SetSeed(); var noise = new SimplexNoise(Random.Range(0, 1000)); _map = noise.CreateSinusMap(resolution, octaves, frequency, amplitude, seamless); }
private void _generateTerrain() { try { IGenerator generator = null; switch (_configurationManager.Algorithm) { case GeneratorAlgorithm.PerlinNoise: generator = new PerlinNoiseGenerator(GraphicsDevice, Graphics, _configurationManager.Parameters); break; case GeneratorAlgorithm.Hill: generator = new HillAlgorithmGenerator(GraphicsDevice, Graphics, _configurationManager.Parameters); break; case GeneratorAlgorithm.Random: generator = new RandomGenerator(GraphicsDevice, Graphics, _configurationManager.Parameters); break; case GeneratorAlgorithm.Rectangle: generator = new RectangleGenerator(GraphicsDevice, Graphics, _configurationManager.Parameters); break; case GeneratorAlgorithm.Voronoi: generator = new VoronoiGenerator(GraphicsDevice, Graphics, _configurationManager.Parameters); break; case GeneratorAlgorithm.SimplexNoise: generator = new SimplexNoise(GraphicsDevice, Graphics, _configurationManager.Parameters); break; case GeneratorAlgorithm.DiamondSquare: generator = new DiamondSquareGenerator(GraphicsDevice, Graphics, _configurationManager.Parameters); break; case GeneratorAlgorithm.RandomWalk: generator = new RandomWalkGenerator(GraphicsDevice, Graphics, _configurationManager.Parameters); break; case GeneratorAlgorithm.DrunkardWalk: generator = new DrunkardWalk(GraphicsDevice, Graphics, _configurationManager.Parameters); break; default: throw new NotImplementedException("Unknown algorithm"); } if (generator == null) { throw new NullReferenceException("Generator cannot be null"); } var timeStart = System.DateTime.Now; Scene.AddObjectToRender(generator.Generate()); Logger.Log.Info("Generated time = " + (DateTime.Now - timeStart).TotalMilliseconds + " ms for " + _configurationManager.Algorithm.ToString()); } catch (Exception e) { Logger.Log.Error(e); throw; } }
public void Initialize(string seed) { Block.CreateAttributes(blocksDefinition); // Seed the generator simplex = new SimplexNoise(seed); // Init vars allChunks = new Dictionary<string, Chunk>(); activeChunks = new List<Chunk>(); chunksToLoad = new PriorityQueue<float, Chunk>(new ChunkDistanceComparer()); // This is obviously not the player's real position, but it forces a chunk update when game starts playerPos = new int[]{999999999,999999999,999999999}; InitializeTextures(); }
private void FixedUpdate() { if (ConfigurationManager.Instance.loadTopColony) { if (Input.GetKeyUp(KeyCode.KeypadPlus)) { topColony.MoveColony(); } return; } if (Input.GetKeyUp(KeyCode.End)) { pause = !pause; } if (pause && !Input.GetKeyUp(KeyCode.KeypadPlus)) { return; } // Update all ants // Must determine when to respawn everything bool allDead = true; // If all colonies dead, regenerate world and colonies foreach (Agents.Colony colony in colonies) { if (!colony.isAllDead()) { allDead = false; // Move all ants according to their environment and nervous system colony.MoveColony(); } } if (allDead) { generation++; float bestFitness = topColony.fitness(); foreach (Agents.Colony colony in colonies) { if (colony.getTotalNestBlocks() > bestFitness) { topColony.DestroyColony(); topColony = colony; bestFitness = colony.fitness(); noNewTopColonySince = generation; } } // Remove all but the best foreach (Agents.Colony colony1 in colonies) { if (colony1 != topColony) { colony1.DestroyColony(); } } Debug.Log("On generation " + generation.ToString() + " the best colony produced " + Mathf.Max(new float[] { colonies[0].getTotalNestBlocks(), colonies[1].getTotalNestBlocks(), colonies[2].getTotalNestBlocks(), colonies[3].getTotalNestBlocks() }).ToString() + " blocks."); Debug.Log("BUT no new top colony since generation " + noNewTopColonySince.ToString() + " with a global best of " + bestFitness.ToString()); Debug.Log("Queen of Top Colony size - nodes: " + topColony.queen.GetComponent <Agents.Ant>().getNervousSystem().nodes.Count.ToString() + " connections " + topColony.queen.GetComponent <Agents.Ant>().getNervousSystem().connections.Count.ToString()); if (bestFitness > prevBestFitness) { prevBestFitness = bestFitness; Serialize(new Agents.SerializableNS(topColony.bestAnt.GetComponent <Antymology.Agents.Ant>().getNervousSystem()), "ant.dat"); Serialize(new Agents.SerializableNS(topColony.queen.GetComponent <Antymology.Agents.Ant>().getNervousSystem()), "queen.dat"); } // Resetting the world if (generation % 10 == 0) { // Reset the world. Every 20 generations RNG = new System.Random((int)Time.time); SimplexNoise = new SimplexNoise((int)Time.time); // Initialize a new 3D array of blocks with size of the number of chunks times the size of each chunk Blocks = new AbstractBlock[ ConfigurationManager.Instance.World_Diameter * ConfigurationManager.Instance.Chunk_Diameter, ConfigurationManager.Instance.World_Height *ConfigurationManager.Instance.Chunk_Diameter, ConfigurationManager.Instance.World_Diameter *ConfigurationManager.Instance.Chunk_Diameter]; for (int i = 0; i < ConfigurationManager.Instance.World_Diameter * ConfigurationManager.Instance.Chunk_Diameter; i++) { for (int j = 0; j < ConfigurationManager.Instance.World_Height * ConfigurationManager.Instance.Chunk_Diameter; j++) { for (int k = 0; k < ConfigurationManager.Instance.World_Diameter * ConfigurationManager.Instance.Chunk_Diameter; k++) { Blocks[i, j, k] = new AirBlock(); } } } GameObject chunks = GameObject.Find("Chunks"); Destroy(chunks); // Initialize a new 3D array of chunks with size of the number of chunks Chunks = new Chunk[ ConfigurationManager.Instance.World_Diameter, ConfigurationManager.Instance.World_Height, ConfigurationManager.Instance.World_Diameter]; GenerateData(); GenerateChunks(); } GenerateAnts(); } }