private static void SmoothMapDoubleLayer(ref GameOfLifeSettings settings) { for (int z = 0; z < height; z++) { for (int x = 0; x < width; x++) { int neighbourWallsCount = GetSurroundingWallsCount(x, z, 1, false); if (neighbourWallsCount > 4) { map[x, z] = true; } int neighbourWallsCountMask = GetSurroundingWallsCountMask(x, z, 1, false); if (neighbourWallsCountMask > 4) { mask[x, z] = true; } } } }
private static void SmoothMap(ref GameOfLifeSettings settings) { for (int z = 0; z < height; z++) { for (int x = 0; x < width; x++) { //Count neighbours int neighboursCount = GetSurroundingWallsCount(x, z, 1, false); if (map[x, z] == true) //if a wall { mask[x, z] = SmoothRuleOne(neighboursCount, settings.destroyWallLimit); } else { mask[x, z] = SmoothRuleTwo(neighboursCount, settings.createWallLimit); } } } // Copy mask to map System.Buffer.BlockCopy(mask, 0, map, 0, sizeof(bool) * width * height); }
public static EmptyGrid ProcessMap(EmptyGrid map, GameOfLifeSettings settings) { // Random Generator Random.State initialState = Random.state; if (settings.useFixedSeed) { Random.InitState(settings.seed.GetHashCode()); } else { Random.InitState(Time.time.ToString().GetHashCode()); } // Get map mask //bool[,] mask = GameOfLife.ProcessMap(map.width, map.height, settings); // Fill with cells //for (int z = 0; z < map.height; z++) //{ // for (int x = 0; x < map.width; x++) // { // if (mask[x, z]) // { // map.values[x, z] = Cell.CreateCell(CellType.Wall); // } // else // { // map.values[x, z] = Cell.CreateCell(CellType.Floor); // } // } //} map.values = GameOfLife.TransformBoolToCell(GameOfLife.ProcessMap(map.width, map.height, settings), CellType.Wall, CellType.Floor); Random.state = initialState; return(map); }
/// TODO: Add null ref checking /// public static bool[,] ProcessMap(int mapWidth, int mapHeight, GameOfLifeSettings settings) { width = mapWidth; height = mapHeight; // Create Mask and Map map = new bool[width, height]; mask = new bool[width, height]; //Initial filling for (int z = 0; z < height; z++) { for (int x = 0; x < width; x++) { if (Random.value < settings.randomFillPercent) { map[x, z] = true; //wall } else { map[x, z] = false; } if (settings.useDoubleLayerGeneration) { if (Random.value < settings.randomFillPercent) { mask[x, z] = true; //wall } else { mask[x, z] = false; } } } } if (settings.useDoubleLayerGeneration) { //Smooth map for (int i = 0; i < settings.smoothCount; i++) { SmoothMapDoubleLayer(ref settings); } //Apply Mask Double Layer for (int x = 0; x < mapWidth; x++) { for (int y = 0; y < mapHeight; y++) { if (map[x, y] && mask[x, y] == true) { map[x, y] = true; //wall } if (map[x, y] && mask[x, y] == false) { map[x, y] = false; } } } } else { //Smooth map for (int i = 0; i < settings.smoothCount; i++) { SmoothMap(ref settings); } } return(map); }