private Queue <SeedAgent> GetSeedAgentQueue(Tuple <int, int> center) { int GetRandomDisplacement() { return(UnityEngine.Random.Range((int)(-SeedSpacing / DisplacementDiv), (int)(SeedSpacing / DisplacementDiv))); } // Create a queue of SeedAgents Queue <SeedAgent> AgentQueue = new Queue <SeedAgent>(); // Enqueue the snow agent SeedAgent snowAgent = SeedAgent.Create(Snow, center.Item1, center.Item2); AgentQueue.Enqueue(snowAgent); void GenerateRadialAgents(uint BiomeType, int radius, int centerX, int centerY) { for (float t = 0; t < 2 * Math.PI; t += 0.01f) { var x = Math.Sin(t) * radius; var y = Math.Cos(t) * radius; SeedAgent agent = SeedAgent.Create(BiomeType, (int)x + centerX + GetRandomDisplacement(), (int)y + centerY + GetRandomDisplacement()); if (agent != null) { AgentQueue.Enqueue(agent); } } } // Generate radial mountain, grass, sand, and water agents GenerateRadialAgents(Mountain, SeedSpacing, snowAgent.GetX(), snowAgent.GetY()); GenerateRadialAgents(Grass, SeedSpacing * 2, snowAgent.GetX(), snowAgent.GetY()); GenerateRadialAgents(Grass, SeedSpacing * 3, snowAgent.GetX(), snowAgent.GetY()); GenerateRadialAgents(Sand, SeedSpacing * 4, snowAgent.GetX(), snowAgent.GetY()); GenerateRadialAgents(Water, SeedSpacing * 5, snowAgent.GetX(), snowAgent.GetY()); return(AgentQueue); }
public Tuple <uint[, ], Tuple <int, int> > GenerateBiome(uint[,] Top, uint[,] Right, uint[,] Bottom, uint[,] Left) { Biome = new uint[BiomeDimensions, BiomeDimensions]; // Make the agent queue Queue <SeedAgent> AgentQueue = new Queue <SeedAgent>(); // Enqueue all adjacent biome seeds for (int Selection = 1; Selection <= 4; Selection++) { SeedAgent newAgent = SeedAgent.Create(0, -1, -1); switch (Selection) { // Top case 1: if (Top == null) { continue; } for (int i = 0; i < BiomeDimensions; i++) { newAgent = SeedAgent.Create(Top[BiomeDimensions - 1, i], 0, i); if (newAgent != null) { AgentQueue.Enqueue(newAgent); } } continue; // Right case 2: if (Right == null) { continue; } for (int i = 0; i < BiomeDimensions; i++) { newAgent = SeedAgent.Create(Right[i, 0], i, BiomeDimensions - 1); if (newAgent != null) { AgentQueue.Enqueue(newAgent); } } continue; // Down case 3: if (Bottom == null) { continue; } for (int i = 0; i < BiomeDimensions; i++) { newAgent = SeedAgent.Create(Bottom[0, i], BiomeDimensions - 1, i); if (newAgent != null) { AgentQueue.Enqueue(newAgent); } } continue; // Left case 4: if (Left == null) { continue; } for (int i = 0; i < BiomeDimensions; i++) { newAgent = SeedAgent.Create(Left[i, BiomeDimensions - 1], i, 0); if (newAgent != null) { AgentQueue.Enqueue(newAgent); } } continue; default: break; } } // Create and enqueue all init seed agents Tuple <int, int> center = new Tuple <int, int>(UnityEngine.Random.Range(2 * (BiomeDimensions / 5), 3 * (BiomeDimensions / 5)), UnityEngine.Random.Range(2 * (BiomeDimensions / 5), 3 * (BiomeDimensions / 5))); Queue <SeedAgent> SeedAgentQueue = GetSeedAgentQueue(center); while (SeedAgentQueue.Count > 0) { AgentQueue.Enqueue(SeedAgentQueue.Dequeue()); } // BFS the AgentQueue, marking adjacent coordinates of Biome while (AgentQueue.Count > 0) { SeedAgent agent = AgentQueue.Dequeue(); //int cycle = UnityEngine.Random.Range(1, 9); SeedAgent newAgent = SeedAgent.Create(0, -1, -1); for (int i = 1; i <= 8; i++) { switch (i) { // Up case 1: newAgent = SeedAgent.Create(agent.GetBiomeType(), agent.GetX() - 1, agent.GetY()); break; // Up-right case 2: newAgent = SeedAgent.Create(agent.GetBiomeType(), agent.GetX() - 1, agent.GetY() + 1); break; // Right case 3: newAgent = SeedAgent.Create(agent.GetBiomeType(), agent.GetX(), agent.GetY() + 1); break; // Down-right case 4: newAgent = SeedAgent.Create(agent.GetBiomeType(), agent.GetX() + 1, agent.GetY() + 1); break; // Down case 5: newAgent = SeedAgent.Create(agent.GetBiomeType(), agent.GetX() + 1, agent.GetY()); break; // Down-left case 6: newAgent = SeedAgent.Create(agent.GetBiomeType(), agent.GetX() + 1, agent.GetY() - 1); break; // Left case 7: newAgent = SeedAgent.Create(agent.GetBiomeType(), agent.GetX(), agent.GetY() - 1); break; // Up-left case 8: newAgent = SeedAgent.Create(agent.GetBiomeType(), agent.GetX() - 1, agent.GetY() - 1); break; // Uh oh default: break; } if (newAgent != null) { AgentQueue.Enqueue(newAgent); } } } return(new Tuple <uint[, ], Tuple <int, int> >(Biome, center)); }