Hi, I’m trying to make a top-down survival game, and for the biome generation I am trying to implement this grown biomes algorithm here. The problem I have is wierd. The code doesn’t return any errors, but most of the time only a handful of biomes show up in the end result (4 to 5 out of 9 total).

I saw that the int Random.Range max values are exclusive so I thought some biome values are being ignored so I bumped them up by one but then it started giving me errors, saying that the index for the biome dictionary did not exist (That’s why the code attached is the old version).

I don’t know what the problem may be. If anyone knows, help is greatly appreciated.

```
public int[,] GrowIteration(int[,] _map){
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GrownBiomes : MonoBehaviour
{
[SerializeField] int iterations;
int[,] map;
Texture2D debugTexture;
Dictionary<int, Color> Biomes = new Dictionary<int, Color>();
// Start is called before the first frame update
void Start()
{
map = new int[3,3];
Biomes.Add(0, Color.green);
Biomes.Add(1, Color.yellow);
Biomes.Add(2, Color.red);
Biomes.Add(3, Color.gray);
Biomes.Add(4, Color.blue);
Biomes.Add(5, Color.black);
Biomes.Add(6, Color.white);
Biomes.Add(7, Color.magenta);
Biomes.Add(8, Color.cyan);
GenerateBiomes(map, iterations, Biomes);
this.GetComponent<MeshRenderer>().material.mainTexture = debugTexture;
}
public void GenerateBiomes(int[,] _map, int _iterations, Dictionary<int, Color> _biomes){
List<int> BiomesToAssign = new List<int>();
for (int i = 0; i < _biomes.Count; i++)
{
BiomesToAssign.Add(i);
}
for (int x = 0; x < _map.GetLength(0); x++)
{
for (int y = 0; y < _map.GetLength(1); y++)
{
int randomIndex = Random.Range(0, BiomesToAssign.Count + 1);
_map[x,y] = randomIndex;
BiomesToAssign.Remove(randomIndex);
}
}
for (int i = 0; i < _iterations; i++)
{
_map = GrowIteration(_map);
}
debugTexture = new Texture2D(_map.GetLength(0), _map.GetLength(1));
for (int x = 0; x < _map.GetLength(0); x++)
{
for (int y = 0; y < _map.GetLength(1); y++)
{
debugTexture.SetPixel(x,y,_biomes[_map[x,y]]);
}
}
debugTexture.Apply();
}
public int[,] GrowIteration(int[,] _map){
//CREATE NEW MAP AND SET VALUE TO NULL
int[,] newMap = new int[(2 * _map.GetLength(0)) - 1, (2 * _map.GetLength(1)) - 1];
for (int x = 0; x < newMap.GetLength(0); x++)
{
for (int y = 0; y < newMap.GetLength(1); y++)
{
newMap[x,y] = -1;
}
}
//COPY VALUES OF OLD MAP INTO CORNERS
for (int x = 0; x < newMap.GetLength(0); x += 2)
{
for (int y = 0; y < newMap.GetLength(1); y += 2)
{
newMap[x,y] = _map[x/2, y/2];
}
}
//CALCULATE INTERMIDIATE VALUES
#region Calculate Values
//RANDOM AMONGST CORNERS
for (int x = 1; x < newMap.GetLength(0); x += 2)
{
for (int y = 1; y < newMap.GetLength(1); y += 2)
{
int[] possibleValues = new int[4];
possibleValues[0] = newMap[x-1,y-1];
possibleValues[1] = newMap[x+1,y-1];
possibleValues[2] = newMap[x-1,y+1];
possibleValues[3] = newMap[x+1,y+1];
int randomIndex = Random.Range(0, 4);
newMap[x,y] = possibleValues[randomIndex];
}
}
//RANDOM AMONGST TOP-BOTTOM
for (int x = 0; x < newMap.GetLength(0); x += 2)
{
for (int y = 1; y < newMap.GetLength(1); y += 2)
{
int[] possibleValues = new int[2];
possibleValues[0] = newMap[x,y-1];
possibleValues[1] = newMap[x,y+1];
int randomIndex = Random.Range(0, 2);
newMap[x,y] = possibleValues[randomIndex];
}
}
//RANDOM AMONGST LEFT-RIGHT
for (int x = 1; x < newMap.GetLength(0); x += 2)
{
for (int y = 0; y < newMap.GetLength(1); y += 2)
{
int[] possibleValues = new int[2];
possibleValues[0] = newMap[x+1,y];
possibleValues[1] = newMap[x-1,y];
int randomIndex = Random.Range(0, 2);
newMap[x,y] = possibleValues[randomIndex];
}
}
#endregion
return newMap;
}
}
}
```