private FloorLayout GenerateBasement() { Cell[,] cellGrid = new Cell[1, 1]; Node node = new Node(0, 0, NodeType.Basement); List <int> possibleDoors = new List <int> { 0, 1, 2, 3 }; int doorStart = possibleDoors[Random.Range(0, possibleDoors.Count)]; possibleDoors.Remove(doorStart); int doorEnd = possibleDoors[Random.Range(0, possibleDoors.Count)]; cellGrid[0, 0] = new Cell(0, 0, CellType.Normal, node); cellGrid[0, 0].doorTypes[doorStart] = DoorType.Start; cellGrid[0, 0].doorTypes[doorEnd] = DoorType.Exit; var layout = new FloorLayout { floorRoomSize = 5, floorLayout = new RoomDefinition[1, 1], cellLayout = cellGrid }; SetSunProperties(ref layout); layout.floorLayout[0, 0] = templateGenerator.GenerateRoom(0, 5, cellGrid[0, 0]); layout.floorLayout[0, 0].visualTheme = SetVisualTheme(0); return(layout); }
public FloorLayout[] GenerateAllFloors(int towerNumber, int numberFloors) { Random.InitState(towerNumber); System.Random dungeonRandom = new System.Random(towerNumber); var floors = new FloorLayout[numberFloors]; try { for (var i = 0; i < numberFloors; i++) { if (i == 0) { floors[i] = GenerateBasement(); } else { floors[i] = GenerateFloor(i, dungeonRandom); } } } catch (Exception e) { Debug.LogError(e); #if UNITY_EDITOR Debug.LogError("There was an error generating the floor definition. Leaving play mode."); UnityEditor.EditorApplication.isPlaying = false; #else Application.Quit(); #endif } return(floors); }
private int GetShortestSolution(FloorLayout startingLayout, int currentDepth) { int depth = currentDepth + 1; if (depth < shortestPath) { foreach (FloorLayout f in startingLayout.PossibleMoves()) { string state = f.ToString(); int depthSeenAt = minDepthForState.GetValueOrDefault(state, int.MaxValue); if (depthSeenAt > depth) { minDepthForState[state] = depth; if (f.IsFinishedLayout()) { shortestPath = depth; } else { GetShortestSolution(f, depth); } } } } return(shortestPath); }
void Start() { layout = new FloorLayout(floorSize, new Point(startRoomX, startRoomY), new RangeInt(minRooms, maxRooms)); using (StreamWriter writetext = File.CreateText("layout.txt")) { writetext.WriteLine(layout); } layout.Apply(constructLists(rooms)); startRoom.StartGame(); }
private FloorLayout GenerateFloor(int floorNum, System.Random randomGen) { var floorSize = SetFloorRoomSize(floorNum); var floorRecipeLength = SetRecipeLength(floorNum); var floorTheme = SetVisualTheme(floorNum); var roomDifficulty = SetRoomDifficulty(floorNum); var recipeName = GetRecipe(); var layout = new FloorLayout { floorRoomSize = floorSize }; DungeonResult results = Program.GenerateDungeon(recipeLength: floorRecipeLength, randomGen: randomGen, recipeName: recipeName); if (results.layoutMap == null) { Debug.Log("Generated layout was invalid."); Application.Quit(); } else { Cell[,] cellGrid = results.layoutMap.Get2DMap(); if (debug) { Debug.Log(results.layoutMap.ToString()); } layout.floorLayout = new RoomDefinition[cellGrid.GetLength(0), cellGrid.GetLength(1)]; for (int i = 0; i < cellGrid.GetLength(0); i++) { for (int j = 0; j < cellGrid.GetLength(1); j++) { if (cellGrid[i, j] != null) { if (cellGrid[i, j].type == CellType.Connection) { cellGrid[i, j].node = new Node(0, 0, NodeType.Connection); } layout.floorLayout[i, j] = templateGenerator.GenerateRoom(roomDifficulty, floorSize, cellGrid[i, j]); layout.floorLayout[i, j].visualTheme = floorTheme; layout.floorLayout[i, j].roomType = cellGrid[i, j].node.type; } } } layout.cellLayout = cellGrid; } SetSunProperties(ref layout); return(layout); }
private FloorLayout(FloorLayout original) { elevatorFloor = original.elevatorFloor; floorCount = original.floorCount; floorComponents = new List <List <int> >(); foreach (List <int> floor in original.floorComponents) { floorComponents.Add(floor.Clone()); } }
private void SetSunProperties(ref FloorLayout layout) { var rangeSet = new[] { Random.Range(23f, 77f), Random.Range(109f, 164f), Random.Range(199f, 243f), Random.Range(291f, 337f) }; if (environmentParameters.lightingType == LightingType.Extreme) { layout.sunRotation = Quaternion.Euler( Random.Range(0, 90), rangeSet[Random.Range(0, rangeSet.Length)], 0); layout.sunIntensity = Random.Range(0f, 10f); layout.sunColor = new Color( Random.Range(0.0f, 1f), Random.Range(0.0f, 1f), Random.Range(0.0f, 1f)); } else { layout.sunRotation = Quaternion.Euler( Random.Range(23, 77), rangeSet[Random.Range(0, rangeSet.Length)], 0); layout.sunIntensity = Random.Range(3f, 7f); layout.sunColor = new Color( Random.Range(0.65f, 1f), Random.Range(0.8f, 1f), Random.Range(0.8f, 1f)); } }
public Day11() : base(11, 2016, "") { FloorLayout startingLayout = new FloorLayout(realInput); Queue <(FloorLayout floors, int depth)> layoutsToCheck = new Queue <(FloorLayout f, int depth)>(); layoutsToCheck.Enqueue((startingLayout, 1)); bool matchFound = false; while (!matchFound) { var layout = layoutsToCheck.Dequeue(); foreach (FloorLayout child in layout.floors.PossibleMoves()) { string state = child.ToString(); int depthSeenAt = minDepthForState.GetValueOrDefault(state, int.MaxValue); if (depthSeenAt > layout.depth) { minDepthForState[state] = layout.depth; if (child.IsFinishedLayout()) { shortestPath = layout.depth; matchFound = true; } else { layoutsToCheck.Enqueue((child, layout.depth + 1)); } } } } partOne = shortestPath.ToString(); }