// Generates a stack containing the successors of the current configuration // curPos will be moved to the location of the space you just placed private Stack GetSuccessors() { Stack successors = new Stack(); for (int row = -1; row <= 1; row++) { for (int col = -1; col <= 1; col++) { if ((Mathf.Abs(row) + Mathf.Abs(col)) != 1) { continue; // if not up down left or right of the current position } Vector2 newPos = new Vector2(curPosition.x + row, curPosition.y + col); if (GameManager.ContainsCoords(visited, newPos)) { continue; // skip current space if already visited } LayoutValidator newValidator = new LayoutValidator(); newValidator.curPosition = newPos; visited.Add(newValidator.curPosition); successors.Push(newValidator); } } return(successors); }
// Use this for initialization void Start() { if (Constants.TEST_NAME_GENERATION) { NameGeneratorTester.testGeneration(); } if (Constants.VALIDATE_LAYOUTS) { try{ LayoutValidator.runValidation(); }catch (Exception e) { TestLogger.log("WrongLayoutDeclarationException: " + e.Message); } } if (Constants.VALIDATE_ROOMS) { try{ RoomValidator.runValidation(); }catch (WrongRoomDeclarationException e) { TestLogger.log("WrongRoomDeclarationException: " + e.Message); } } if (Constants.TEST_DUNGEON_GENERATION) { DungeonGenerationTester.testGeneration(); } }
public void LayoutValidatorContentPaneTest() { // no content pane Assert.False(LayoutValidator.IsValid( @"<div class=""row""> <div id=""AsidePane"" runat=""server"" /> </div>" )); }
public void LayoutValidatorFormattingTest() { // formatting error - no closing tag Assert.False(LayoutValidator.IsValid( @"<div class=""row""> <div id=""ContentPane"" runat=""server"" /> <div>" )); }
public void LayoutValidatorUniquePanesTest() { // two panes with same Assert.False(LayoutValidator.IsValid( @"<div class=""row""> <div id=""ContentPane"" runat=""server"" /> <div id=""AsidePane"" runat=""server"" /> <div id=""AsidePane"" runat=""server"" /> </div>" )); }
public IActionResult AddNewIcu([FromBody] Icu icu) { try { if (!LayoutValidator.CheckIfLayoutIsPresent(icu.LayoutId)) { return(BadRequest("The Inserted Layout Id For The ICU is Not Available")); } else { _context.Add(icu); _context.SaveChanges(); return(Ok()); } } catch (Exception) { return(StatusCode(500)); } }
/// <summary> /// Handles Click event for Update button /// </summary> /// <param name='sender'> /// Sender. /// </param> /// <param name='e'> /// Event args. /// </param> protected void buttonUpdate_Click(object sender, EventArgs e) { try { var layoutName = textLayoutName.Text.Trim(); var originalLayoutName = hiddenLayoutName.Value; var layoutPortaId = int.Parse(hiddenPortalId.Value); var layoutFile = LayoutHelper.GetLayoutFileName(layoutName, layoutPortaId); if (layoutName != originalLayoutName && File.Exists(layoutFile)) { WarningMessage("LayoutFileAlreadyExists.Warning"); return; } if (!LayoutValidator.IsValid(layoutEditor.Text)) { WarningMessage("LayoutMarkupIsInvalid.Warning"); return; } // ensure layouts directory exists var layoutsDirectory = Path.GetDirectoryName(layoutFile); if (!Directory.Exists(layoutsDirectory)) { Directory.CreateDirectory(layoutsDirectory); } File.WriteAllText(layoutFile, layoutEditor.Text); LayoutHelper.GetManager().ResetLayout(layoutPortaId, layoutName); ModuleController.SynchronizeModule(ModuleId); Response.Redirect(Globals.NavigateURL(), true); } catch (Exception ex) { Exceptions.ProcessModuleLoadException(this, ex); } }
// Uses the InitObstacles from the initList to generate a queue of InitObjects to be // Initialized later. After this step, all Queued InitObjects should be valid and ready to place. private void QueueInitObstacles() { initQueue = new Queue(); ArrayList occupiedCoordinates = new ArrayList(); // Contains Vector2s representing the occupied spaces in the grid LayoutValidator validator = new LayoutValidator(boardDim); // The validator that will validate the layout of the objects in the queue after they are placed occupiedCoordinates.Add(new Vector2(0, 0)); // Occupy player spawn occupiedCoordinates.Add(new Vector2(boardDim - 1, boardDim - 1)); // Occupy goal //Occupy one block adjacent to player start and finish to increase chance of successful generation Vector2 playerStartOcc; playerStartOcc = Random.Range(0, 1) > 0 ? new Vector2(1f, 0f) : new Vector2(0f, 1f); Vector2 playerFinishOcc; playerFinishOcc = Random.Range(0, 1) > 0 ? new Vector2(boardDim - 1, boardDim - 2) : new Vector2(boardDim - 2, boardDim - 1); occupiedCoordinates.Add(playerFinishOcc); occupiedCoordinates.Add(playerStartOcc); InitObstacle iob; while (preInitQueue.Count > 0) { iob = (InitObstacle)preInitQueue.Dequeue(); Vector2 iobCoords = new Vector2(iob.getRow(), iob.getCol()); if (!iob.OutOfBounds(boardDim) && !ContainsCoords(occupiedCoordinates, iobCoords)) { initQueue.Enqueue(iob); occupiedCoordinates.Add(iobCoords); // Occupy this object's coordinates validator.AddObstacle(iob); } else if (!debug) { // Add a new initObstacle of the same type to the initList int randRow = Random.Range(0, boardDim); int randCol = Random.Range(0, boardDim); preInitQueue.Enqueue(new InitObstacle(iob.GetCode(), randRow, randCol)); } else { Debug.Log(iob + " Not added to initQueue."); } } // Place the Button and Door if needed Debug.Log("Validator:\n" + validator.ToString()); IOrderedEnumerable <Vector2> doorPlaces = validator.FindDoorPlacement().OrderBy(e => Random.Range(0, 100)); foreach (Vector2 pos in doorPlaces) { // See if adding the door would make the new layout unsolvable // but use an blocking obstacle to test if the door would have any affect iob = new InitObstacle('b', (int)pos.x, (int)pos.y); validator.AddObstacle(iob); validator.ResetVisited(); // If it is not solvable, then placing the door at the location makes it required to pass if (!validator.IsSolvable()) { iob = new InitObstacle('d', (int)pos.x, (int)pos.y); // Determine places the button can be placed List <Vector2> visited = new ArrayList(validator.GetVisited()).Cast <Vector2>().ToList(); // Copy visited list so we can remove elements later visited.RemoveAll(e => e.x < 0 || e.x >= boardDim); // Remove all x out of bounds visited.RemoveAll(e => e.y < 0 || e.y >= boardDim); // Remove all y out of bounds visited.RemoveAll(e => e.x + e.y < 2); // Remove spaces adjacent to player spawn visited.RemoveAll(e => e == pos); // Remove location of the door itself visited.RemoveAll(e => !validator.NullAtPos(e)); // Remove all occupied spaces if (visited.Count > 0) { buttonPos = visited[Random.Range(0, visited.Count)]; initQueue.Enqueue(iob); Debug.Log("ButtonPos: " + buttonPos); Debug.Log("DoorPos: " + pos); } else { Debug.Log("Button not instantiated! No Valid places for it."); } validator.RemoveAtPos(pos); // remove so break works break; } validator.RemoveAtPos(pos); // remove so it can be solvable going forward } // Place coins if in progression mode GameObject progressionManager = GameObject.Find("ProgressionManager"); int numCoins; if (progressionManager != null) { validator.ResetVisited(); numCoins = progressionManager.GetComponent <ProgressionManager>().GetNumberOfCoins(); List <Vector2> coinPlaces = validator.FindCoinPlacement(); coinPlaces.Remove(new Vector2(0, 0)); coinPlaces.Remove(new Vector2(boardDim - 1, boardDim - 1)); Vector2 curPlace; int randomPos; for (int i = 0; i < numCoins && coinPlaces.Count > 0; i++) { randomPos = Random.Range(0, coinPlaces.Count - 1); curPlace = coinPlaces[randomPos]; initQueue.Enqueue(new InitObstacle('c', (int)curPlace.x, (int)curPlace.y)); coinPlaces.RemoveAt(randomPos); } } // Determine if a valid configuration was generated if (!debug) { validator.ResetVisited(); if (!validator.IsSolvable()) { Debug.Log("Invalid configuration generated!\n" + validator.ToString()); generationFailures++; if (generationFailures >= failGenerationsTimeoutCount) { Debug.Log("Generation timed out after " + generationFailures + " failures."); return; // Exit if maximum generation failures is met } RandomList(); QueueInitObstacles(); return; } } Debug.Log("Queueing finished successfully"); }
public void LayoutTest(string layoutFile) { Assert.True(LayoutValidator.IsValid(File.ReadAllText(layoutFile))); }