public void FlockingSeparationTest1() { CellGenerator cellGenerator = new CellGenerator(); List <Cell> cells = cellGenerator.GenerateCellList(150, 50, 250, 750); //List<Cell> rearrangedCells = CellProcessor.FlockingSeparation(cells, cells.Count * 2); List <Cell> rearrangedCells = null; while (true) { try { rearrangedCells = CellProcessor.FlockingSeparation(cells, cells.Count * 2); break; } catch (OutOfIterationException exception) { Console.WriteLine("WARNING: Separation iteration has been exhausted. " + "Iteration limit is " + exception.IterationNumber + ". Retrying with new dataset ...\n"); cells = cellGenerator.GenerateCellList(150, 50, 250, 750); } } foreach (Cell cell in rearrangedCells) { foreach (Cell otherCell in rearrangedCells) { if (cell == otherCell) { continue; } Assert.IsFalse(cell.CheckCollision(otherCell)); } } Console.WriteLine("Separation and checking successful. It's clear."); }
public void Regenerate() { for (var x = 0; x < Dimensions.Width; x++) { for (var y = 0; y < Dimensions.Height; ++y) { _elementMatrix[x][y] = CellGenerator.Generate(this, new Coordinates2D(x, y)); } } }
public ClickToDevelopCell( CellGenerator cellGenerator, CellMapper cellMapper, int replaceCellRecordId, int blankCellRecordId, int generateBlankRange ) { this.cellGenerator = cellGenerator; this.cellMapper = cellMapper; this.replaceCellRecordId = replaceCellRecordId; this.blankCellRecordId = blankCellRecordId; this.generateBlankRange = generateBlankRange; }
public void SetBordersAsDecoration() { foreach (Transform item in cellParent) { CellGenerator cell = item.GetComponent <CellGenerator>(); // Is a border if ((cell.mKCellData.PosX == 0) || (cell.mKCellData.PosX == 14) || (cell.mKCellData.PosY == 0) || (cell.mKCellData.PosY == 9) || ((cell.mKCellData.PosX == 7) && (this.levelNumber != "6"))) // -> middle border (except in level 6) { if (cell.mKCellData.Type != EMKCellType.Button) // do NOT override the Buttons { cell.mKCellData.Type = EMKCellType.Decoration; } } } }
static void Main(string[] args) { int rows = 100; int collumns = 100; int howManyCells = 1000; CellRandomizer randomizer = new CellRandomizer(rows, collumns); var randomCellID = randomizer.GenerateRandomNumbers(howManyCells); CellGenerator cellGenerator = new CellGenerator(); var cellList = cellGenerator.CellListGenerator(rows, collumns, randomCellID); DeadOrAliveStatusUpdater updater = new DeadOrAliveStatusUpdater(rows, collumns); while (true) { GUIWriter.WriteGui(collumns, cellList); Console.ReadKey(); Console.Clear(); cellList = updater.CellListUpdater(cellList); } }
public DevelopCellActions( CellGenerator cellGenerator, CellMapper cellMapper, int replaceCellRecordId, int blankCellRecordId, int generateBlankRange, GameCameraController gameCameraController ) : base( null, null, new ClickToDevelopCell( cellGenerator, cellMapper, replaceCellRecordId, blankCellRecordId, generateBlankRange ), new DragToMoveCamera(gameCameraController), null ) { }
void Start() { instance = this; _CountCellHit = 0; }
static void Main(string[] args) { Console.WriteLine("Initializing ..."); CellGenerator cellGenerator = new CellGenerator(); Console.WriteLine("Generating dungeons with 150 rooms ..."); /** * ========================================================================= * STEP 1 * ========================================================================= */ List <Cell> cells = cellGenerator.GenerateCellList(150, 50, 250, 750, 50, 1, 0.2); // Draw first step Console.WriteLine("Drawing first step to image ..."); // Generate image with background Image image = new Bitmap(CANVAS_SIZE_X, CANVAS_SIZE_Y); Graphics graph = Graphics.FromImage(image); graph.Clear(Color.White); // Ready pen and draw the cells Pen pen = new Pen(Brushes.Black); //foreach (Cell cell in cells) { foreach (Cell cell in cells) { DrawCube(ref graph, ref pen, cell, image.Width, image.Height); } Console.WriteLine("Image drawn. Saving ..."); if (File.Exists("step1.png")) { File.Delete("step1.png"); Console.WriteLine("Previous save file has been deleted."); } image.Save("step1.png", System.Drawing.Imaging.ImageFormat.Png); Console.WriteLine("Image has been saved as \"step1.png\""); /** * ========================================================================= * STEP 2 * ========================================================================= */ //List<Cell> rearrangedCells = CellProcessor.FlockingSeparation(cells, cells.Count * 2); List <Cell> rearrangedCells; while (true) { try { rearrangedCells = CellProcessor.FlockingSeparation(cells, cells.Count * 2); break; } catch (OutOfIterationException exception) { Console.WriteLine("WARNING: Separation iteration has been exhausted. " + "Iteration limit is " + exception.IterationNumber + ". Retrying with new dataset ...\n"); //cells = cellGenerator.GenerateCellList(150, 50, 250, 750); cells = cellGenerator.GenerateCellList(150, 50, 250, 750, 1, 0.2); } } // Draw second step Console.WriteLine("Drawing second step to image ..."); // Generate image with background image = new Bitmap(CANVAS_SIZE_X, CANVAS_SIZE_Y); graph = Graphics.FromImage(image); graph.Clear(Color.White); //foreach (Cell cell in cells) { foreach (Cell cell in rearrangedCells) { DrawCube(ref graph, ref pen, cell, image.Width, image.Height); } Console.WriteLine("Image drawn. Saving ..."); if (File.Exists("step2.png")) { File.Delete("step2.png"); Console.WriteLine("Previous save file has been deleted."); } image.Save("step2.png", System.Drawing.Imaging.ImageFormat.Png); Console.WriteLine("Image has been saved as \"step2.png\""); /** * ========================================================================= * STEP 3 * ========================================================================= */ List <Cell> selectedCells = CellProcessor.TrimCells(rearrangedCells, 25); // Draw second step Console.WriteLine("Drawing third step to image ..."); // Generate image with background image = new Bitmap(CANVAS_SIZE_X, CANVAS_SIZE_Y); graph = Graphics.FromImage(image); graph.Clear(Color.White); //foreach (Cell cell in cells) { foreach (Cell cell in selectedCells) { DrawCube(ref graph, ref pen, cell, image.Width, image.Height); } Console.WriteLine("Image drawn. Saving ..."); if (File.Exists("step3.png")) { File.Delete("step3.png"); Console.WriteLine("Previous save file has been deleted."); } image.Save("step3.png", System.Drawing.Imaging.ImageFormat.Png); Console.WriteLine("Image has been saved as \"step3.png\""); /** * ========================================================================= * STEP 4.1 * ========================================================================= */ TunnelGenerator tunnelGenerator = new TunnelGenerator(selectedCells); tunnelGenerator.DelaunayTriangulation(); List <Cell> triangulatedCells = tunnelGenerator.ExportCells(); // Draw step Console.WriteLine("Drawing fourth step phase one to image ..."); // Generate image with background image = new Bitmap(CANVAS_SIZE_X, CANVAS_SIZE_Y); graph = Graphics.FromImage(image); graph.Clear(Color.White); // Draw the boxes. foreach (Cell cell in selectedCells) { DrawCube(ref graph, ref pen, cell, image.Width, image.Height); } // Change pen color to difference the lines. pen = new Pen(Brushes.Red); foreach (Cell cell in triangulatedCells) { var foundCells = triangulatedCells.Where(o => cell != o && cell.ConnectedCell.Contains(o.GetHashCode())); foreach (Cell foundCell in foundCells) { DrawLineFromCells(ref graph, ref pen, cell, foundCell, CANVAS_SIZE_X, CANVAS_SIZE_Y); } } Console.WriteLine("Image drawn. Saving ..."); if (File.Exists("step4.1.png")) { File.Delete("step4.1.png"); Console.WriteLine("Previous save file has been deleted."); } image.Save("step4.1.png", System.Drawing.Imaging.ImageFormat.Png); Console.WriteLine("Image has been saved as \"step4.1.png\""); /** * ========================================================================= * STEP 4.2 * ========================================================================= */ tunnelGenerator.RemoveOverlapping(); triangulatedCells = tunnelGenerator.ExportCells(); // Draw step Console.WriteLine("Drawing fourth step phase two to image ..."); // Generate image with background image = new Bitmap(CANVAS_SIZE_X, CANVAS_SIZE_Y); graph = Graphics.FromImage(image); graph.Clear(Color.White); pen = new Pen(Brushes.Black); // Draw the boxes. foreach (Cell cell in selectedCells) { DrawCube(ref graph, ref pen, cell, image.Width, image.Height); } // Change pen color to difference the lines. pen = new Pen(Brushes.Red); foreach (Cell cell in triangulatedCells) { var foundCells = triangulatedCells.Where(o => cell != o && cell.ConnectedCell.Contains(o.GetHashCode())); foreach (Cell foundCell in foundCells) { DrawLineFromCells(ref graph, ref pen, cell, foundCell, CANVAS_SIZE_X, CANVAS_SIZE_Y); } } Console.WriteLine("Image drawn. Saving ..."); if (File.Exists("step4.2.png")) { File.Delete("step4.2.png"); Console.WriteLine("Previous save file has been deleted."); } image.Save("step4.2.png", System.Drawing.Imaging.ImageFormat.Png); Console.WriteLine("Image has been saved as \"step4.2.png\""); /** * ========================================================================= * STEP 4.3 * ========================================================================= */ tunnelGenerator.TrimCellConnections(); tunnelGenerator.TrimCellConnections(); triangulatedCells = tunnelGenerator.ExportCells(); // Draw step Console.WriteLine("Drawing fourth step phase three to image ..."); // Generate image with background image = new Bitmap(CANVAS_SIZE_X, CANVAS_SIZE_Y); graph = Graphics.FromImage(image); graph.Clear(Color.White); pen = new Pen(Brushes.Black); // Draw the boxes. foreach (Cell cell in selectedCells) { DrawCube(ref graph, ref pen, cell, image.Width, image.Height); } // Change pen color to difference the lines. pen = new Pen(Brushes.Red); foreach (Cell cell in triangulatedCells) { var foundCells = triangulatedCells.Where(o => cell != o && cell.ConnectedCell.Contains(o.GetHashCode())); foreach (Cell foundCell in foundCells) { DrawLineFromCells(ref graph, ref pen, cell, foundCell, CANVAS_SIZE_X, CANVAS_SIZE_Y); } } Console.WriteLine("Image drawn. Saving ..."); if (File.Exists("step4.3.png")) { File.Delete("step4.3.png"); Console.WriteLine("Previous save file has been deleted."); } image.Save("step4.3.png", System.Drawing.Imaging.ImageFormat.Png); Console.WriteLine("Image has been saved as \"step4.3.png\""); /** * ========================================================================= * STEP 4.5 * ========================================================================= */ //tunnelGenerator.RemoveOverlapping(); //triangulatedCells = tunnelGenerator.ExportCells(); List <Tunnel> tunnels = tunnelGenerator.GenerateTunnel(); // Draw step Console.WriteLine("Drawing fourth step phase five to image ..."); // Generate image with background image = new Bitmap(CANVAS_SIZE_X, CANVAS_SIZE_Y); graph = Graphics.FromImage(image); graph.Clear(Color.White); pen = new Pen(Brushes.Black); // Draw the boxes. foreach (Cell cell in selectedCells) { DrawCube(ref graph, ref pen, cell, image.Width, image.Height); } // Change pen color to difference the lines. pen = new Pen(Brushes.Blue); // TODO: It sometimes break for some reason. foreach (Tunnel tunnel in tunnels) { var a = triangulatedCells.Single(cell => cell.GetHashCode() == tunnel.CellHashA).LocationCenter; var b = triangulatedCells.Single(cell => cell.GetHashCode() == tunnel.CellHashB).LocationCenter; DrawLineFromPoints(ref graph, ref pen, a, tunnel.AnglePoint.First(), CANVAS_SIZE_X, CANVAS_SIZE_Y); DrawLineFromPoints(ref graph, ref pen, b, tunnel.AnglePoint.Last(), CANVAS_SIZE_X, CANVAS_SIZE_Y); } Console.WriteLine("Image drawn. Saving ..."); if (File.Exists("step4.5.png")) { File.Delete("step4.5.png"); Console.WriteLine("Previous save file has been deleted."); } image.Save("step4.5.png", System.Drawing.Imaging.ImageFormat.Png); Console.WriteLine("Image has been saved as \"step4.5.png\""); /** * ========================================================================= * STEP 5 * ========================================================================= */ //var gridProcessor = new GridConverterAsync(triangulatedCells, tunnels, 200, 200); var gridProcessor = new GridConverter(triangulatedCells, tunnels, 150, 150); //var tunnelLayerTask = gridProcessor.CreateTunnelLayer(); //var cellWallLayerTask = gridProcessor.CreateCellWallLayer(); //var cellLayerTask = gridProcessor.CreateCellLayer(); //tunnelLayerTask.Wait(); //cellWallLayerTask.Wait(); //cellLayerTask.Wait(); //var tunnelLayer = tunnelLayerTask.Result; //var cellWallLayer = cellWallLayerTask.Result; //var cellLayer = cellLayerTask.Result; //var tunnelLayer = gridProcessor.CreateTunnelLayer(); var tunnelLayer = gridProcessor.CreateTunnelLayerSimple(); var cellWallLayer = gridProcessor.CreateCellWallLayer(); //var cellWallLayer = gridProcessor.CreateCellWallLayerSimple(); var cellLayer = gridProcessor.CreateCellLayer(); var connectionLayer = GridConverter.IntersectGrid(tunnelLayer, cellWallLayer, procedural_dungeon_generator.Common.BlockType.RoomConnector); //var gridResult = GridConverterAsync.MergeGrid(tunnelLayer, // cellLayer); //gridResult = GridConverterAsync.MergeGrid(gridResult, cellWallLayer); //gridResult = GridConverterAsync.GenerateConnections(gridResult); var gridResult = GridConverter.MergeGrid(tunnelLayer, cellLayer); gridResult = GridConverter.MergeGrid(gridResult, cellWallLayer); //gridResult = GridConverter.GenerateConnections(gridResult); gridResult = GridConverter.MergeGrid(gridResult, connectionLayer); gridResult = GridConverter.VerifyConnections(gridResult); // Draw step Console.WriteLine("Drawing fifth step to image ..."); // Generate image with background image = new Bitmap(CANVAS_SIZE_X, CANVAS_SIZE_Y); graph = Graphics.FromImage(image); graph.Clear(Color.White); pen = new Pen(Brushes.Black); // Get block size. int blockWidth = CANVAS_SIZE_X / gridResult.Width; int blockHeight = CANVAS_SIZE_Y / gridResult.Height; // Draw the boxes. for (int width = 0; width < gridResult.Width; width++) { for (int height = 0; height < gridResult.Height; height++) { // Draw the colored boxes first. switch (gridResult[width, height].Type) { case procedural_dungeon_generator.Common.BlockType.Room: FillCube(ref graph, Brushes.DarkGreen, new Cell(blockWidth - 2, blockHeight - 2, width * blockWidth + 1, height * blockHeight + 1)); break; case procedural_dungeon_generator.Common.BlockType.Tunnel: FillCube(ref graph, Brushes.DarkGray, new Cell(blockWidth - 2, blockHeight - 2, width * blockWidth + 1, height * blockHeight + 1)); break; case procedural_dungeon_generator.Common.BlockType.RoomWall: FillCube(ref graph, Brushes.Green, new Cell(blockWidth - 2, blockHeight - 2, width * blockWidth + 1, height * blockHeight + 1)); break; case procedural_dungeon_generator.Common.BlockType.RoomConnector: FillCube(ref graph, Brushes.GreenYellow, new Cell(blockWidth - 2, blockHeight - 2, width * blockWidth + 1, height * blockHeight + 1)); break; default: break; } // Then draw the box. DrawCubeNoText(ref graph, ref pen, new Cell(blockWidth, blockHeight, width * blockWidth, height * blockHeight)); } } Console.WriteLine("Image drawn. Saving ..."); if (File.Exists("step5.png")) { File.Delete("step5.png"); Console.WriteLine("Previous save file has been deleted."); } image.Save("step5.png", System.Drawing.Imaging.ImageFormat.Png); Console.WriteLine("Image has been saved as \"step5.png\""); Console.WriteLine("\n\nDebug Log:\n"); triangulatedCells.ForEach(o => Console.WriteLine($"{o}")); }
public void CellGenerationTest1() { CellGenerator generator = new CellGenerator(); }
public void GenerateMap() { if (terrainGenerationType == TerrainGenerationType.PerlinNoise) { if (useRandomSeed) { seed = UnityEngine.Random.Range(-9999, 9999); } float[,] noiseMap = Noise.GenerateNoiseMap(mapWidth, mapHeight, seed, noiseScale, octaves, persistence, lacunarity, offset); if (useFalloffMap) { falloffMap = FalloffGenerator.GenerateFalloffMap(mapWidth, mapHeight); for (int i = 0; i < mapWidth; i++) { for (int j = 0; j < mapHeight; j++) { noiseMap[i, j] = Mathf.Clamp01(noiseMap[i, j] - falloffMap[i, j]); } } } //deepWater if (useFalloffMap == false) { for (int i = 1; i < mapWidth - 1; i++) { for (int j = 1; j < mapHeight - 1; j++) { if (noiseMap[i, j] < 0.19f) { int connectedHeight = 0; for (int a = i - 1; a <= i + 1; a++) { for (int b = j - 1; b <= j + 1; b++) { if (noiseMap[a, b] < 0.19f) { connectedHeight++; } } } if (connectedHeight < 6) { noiseMap[i, j] = UnityEngine.Random.Range(0.19f, 0.28f); } } } } //water for (int i = 1; i < mapWidth - 1; i++) { for (int j = 1; j < mapHeight - 1; j++) { if (noiseMap[i, j] < 0.29f && noiseMap[i, j] > 0.18f) { int connectedHeight = 0; for (int a = i - 1; a <= i + 1; a++) { for (int b = j - 1; b <= j + 1; b++) { if (noiseMap[a, b] < 0.29f) { connectedHeight++; } } } if (connectedHeight < 6) { noiseMap[i, j] = UnityEngine.Random.Range(0.32f, 0.35f); } } } } //sand for (int i = 1; i < mapWidth - 1; i++) { for (int j = 1; j < mapHeight - 1; j++) { if (noiseMap[i, j] < 0.32f && noiseMap[i, j] > 0.28f) { int connectedHeight = 0; for (int a = i - 1; a <= i + 1; a++) { for (int b = j - 1; b <= j + 1; b++) { if (noiseMap[a, b] < 0.32f) { connectedHeight++; } } } if (connectedHeight < 6) { noiseMap[i, j] = UnityEngine.Random.Range(0.32f, 0.34f); } } } } } noiseMapBlocked = new int[mapWidth, mapHeight]; for (int i = 0; i < mapWidth; i++) { for (int j = 0; j < mapHeight; j++) { if (noiseMap[i, j] <= 0.31f || noiseMap[i, j] >= 0.5f) { noiseMapBlocked[i, j] = 1; } else if (i == 0 || i == mapWidth || j == mapWidth || j == 0) { noiseMapBlocked[i, j] = 1; } else { noiseMapBlocked[i, j] = 0; } } } System.Random rng = new System.Random(); housingWidthStart = rng.Next(1, mapWidth - housingWidth); housingHeightStart = rng.Next(1, mapHeight - housingHeight); bool canExit = false; avgHeight = 0; int blockedCounter = 0; for (int z = 0; z < 10000; z++) { if (canExit == true) { break; } canExit = true; avgHeight = 0; blockedCounter = 0; for (int i = housingWidthStart; i < housingWidthStart + housingWidth; i++) { for (int j = housingHeightStart; j < housingHeightStart + housingHeight; j++) { if (noiseMap[i, j] < 0.32f || noiseMap[i, j] > 0.5f) { blockedCounter++; if (blockedCounter > (housingWidth * housingHeight) / 20) { canExit = false; avgHeight = 0; housingWidthStart = rng.Next(1, mapWidth - housingWidth); housingHeightStart = rng.Next(1, mapHeight - housingHeight); } } else { avgHeight += noiseMap[i, j]; } } } } avgHeight = avgHeight / (housingWidth * housingHeight - blockedCounter); //if (avgHeight > 0.49f) // avgHeight = 0.49f; //else if (avgHeight < 0.33f) // avgHeight = 0.33f; for (int i = housingWidthStart - 1; i < housingWidthStart + housingWidth + 1; i++) { for (int j = housingHeightStart - 1; j < housingHeightStart + housingHeight + 1; j++) { if (noiseMapBlocked[i, j] == 1) { int connectedBlocks = 0; for (int x = i - 1; x < i + 1; x++) { for (int y = j - 1; y < j + 1; y++) { if (x == i && y == j) { continue; } else if (noiseMapBlocked[x, y] == 1) { connectedBlocks++; } } } if (connectedBlocks == 0) { noiseMap[i, j] = avgHeight; } if (noiseMap[i, j] > avgHeight + 0.07f) { noiseMap[i, j] = UnityEngine.Random.Range(avgHeight + 0.03f, avgHeight + 0.07f); } } else { noiseMap[i, j] = avgHeight; //Debug.Log("Set avgHeight"); } } } //make an array with a size of the height of the map times the width of the map so each element in the array represents a pixel Color[] colorMap = new Color[mapWidth * mapHeight]; for (int y = 0; y < mapHeight; y++) { for (int x = 0; x < mapWidth; x++) { float currentHeight = noiseMap[x, y]; for (int i = 0; i < regions.Length; i++) { if (currentHeight <= regions[i].height) { colorMap[y * mapWidth + x] = regions[i].color; break; } } } } noiseMapCopy = new float[mapWidth, mapHeight]; for (int i = 0; i < mapWidth; i++) { for (int j = 0; j < mapHeight; j++) { noiseMapCopy[i, j] = noiseMap[i, j]; } } for (int i = 0; i < mapWidth; i++) { for (int j = 0; j < mapHeight; j++) { if (noiseMap[i, j] <= 0.31f || noiseMap[i, j] >= 0.4f) { noiseMapBlocked[i, j] = 1; } else if (i == 0 || i == mapWidth || j == mapWidth || j == 0) { noiseMapBlocked[i, j] = 1; } else { noiseMapBlocked[i, j] = 0; } } } int[,] blockedNodes = new int[mapWidth, mapHeight]; for (int i = 0; i < mapWidth; i++) { for (int j = 0; j < mapHeight; j++) { if (noiseMapBlocked[i, j] == 1) { blockedNodes[i, j] = 1; } else { blockedNodes[i, j] = 0; } } } for (int i = 1; i < mapWidth - 1; i++) { for (int j = 1; j < mapHeight - 1; j++) { if (blockedNodes[i, j] == 1) { for (int k = -1; k < 2; k++) { for (int l = -1; l < 2; l++) { noiseMapBlocked[i + k, j + l] = 1; } } } } } if (shaderMode == ShaderMode.Texture) { shader = Shader.Find("Custom/Terrain"); terrainMaterial.shader = shader; UpdateMeshHeights(terrainMaterial, minHeight, maxHeight); } else if (shaderMode == ShaderMode.Colour) { shader = Shader.Find("Custom/ColourShader"); terrainMaterial.shader = shader; UpdateMeshHeights(terrainMaterial, minHeight, maxHeight); } else { shader = Shader.Find("Standard"); terrainMaterial.shader = shader; } MapDisplay display = FindObjectOfType <MapDisplay>(); if (drawMode == DrawMode.HeightMap) { display.DrawTexture(TextureGenerator.TextureHeightMap(noiseMap)); } else if (drawMode == DrawMode.ColorMap) { display.DrawTexture(TextureGenerator.TextureColorMap(colorMap, mapWidth, mapHeight)); } else if (drawMode == DrawMode.Mesh) { display.DrawMesh(MeshGenerator.GenerateMesh(noiseMap, meshHeightMultiplier, meshHeightCurve), TextureGenerator.TextureColorMap(colorMap, mapWidth, mapHeight)); } //else if (drawMode == DrawMode.FalloffMap) //display.DrawTexture(TextureGenerator.TextureHeightMap(FalloffGenerator.GenerateFalloffMap(mapWidth, mapHeight))); UpdateDraw(); } else { System.Random rng = new System.Random(seed.GetHashCode()); if (useRandomSeed) { seed = UnityEngine.Random.Range(-9999, 9999); } //randomFillPercent = 53; map = new int[mapWidth, mapHeight]; for (int i = 0; i < mapWidth; i++) { for (int j = 0; j < mapHeight; j++) { if (i == 0 || i == mapWidth - 1 || j == 0 || j == mapHeight - 1) { map[i, j] = 1; } else { if (terrainGenerationType == TerrainGenerationType.CellularAutomata) { map[i, j] = (rng.Next(0, 100) < randomFillPercent) ? 1 : 0; } else { map[i, j] = (rng.Next(0, 100) < randomFillPercent) ? 0 : 1; } } } } for (int x = 0; x < 10; x++) { for (int i = 0; i < mapWidth; i++) { for (int j = 0; j < mapHeight; j++) { int neightbourWallTiles = GetSurroundingWallCount(i, j); if (neightbourWallTiles > 4) { map[i, j] = 1; } else if (neightbourWallTiles < 4) { map[i, j] = 0; } } } } ProcessMap(); int borderSize = 1; int[,] borderedMap = new int[mapWidth + borderSize * 2, mapHeight + borderSize * 2]; for (int i = 0; i < borderedMap.GetLength(0); i++) { for (int j = 0; j < borderedMap.GetLength(1); j++) { if (i >= borderSize && i < mapWidth + borderSize && j >= borderSize && j < mapHeight + borderSize) { borderedMap[i, j] = map[i - borderSize, j - borderSize]; } else { borderedMap[i, j] = 1; } } } if (terrainGenerationType == TerrainGenerationType.ReverseCellularAutomata) { for (int i = 0; i < borderedMap.GetLength(0); i++) { for (int j = 0; j < borderedMap.GetLength(1); j++) { if (borderedMap[i, j] == 1) { borderedMap[i, j] = 0; } else { borderedMap[i, j] = 1; } } } } CellGenerator cellGen = cellularAutomata.GetComponent <CellGenerator>(); cellGen.GenerateMesh(borderedMap, 1); } }