public void Test_IsLegalPosition_False() { var mazeFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestMazes\small_maze.txt"); var mazePuzzle = new MazePuzzle(mazeFilePath); //Wall Test Assert.That( () => MazeRunner.IsLegalPosition(mazePuzzle.Maze, new Point(0, 0)), Is.EqualTo(false)); //Out of bounds Negative X value Assert.That( () => MazeRunner.IsLegalPosition(mazePuzzle.Maze, new Point(-1, 0)), Is.EqualTo(false)); //Out of bounds Negative Y value Assert.That( () => MazeRunner.IsLegalPosition(mazePuzzle.Maze, new Point(0, -1)), Is.EqualTo(false)); //Out of bounds Y too large Assert.That( () => MazeRunner.IsLegalPosition(mazePuzzle.Maze, new Point(0, 6)), Is.EqualTo(false)); //Out of bounds X too large Assert.That( () => MazeRunner.IsLegalPosition(mazePuzzle.Maze, new Point(5, 0)), Is.EqualTo(false)); }
public void Test_Move() { var mazeFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestMazes\small_maze.txt"); var mazePuzzle = new MazePuzzle(mazeFilePath); var currentPos = new Point(1, 1); //North---------------------------------- Assert.That( () => MazeRunner.Move(mazePuzzle.Maze, currentPos, MazeRunner.Direction.North), Is.EqualTo(null)); //East---------------------------------- Assert.That( () => MazeRunner.Move(mazePuzzle.Maze, currentPos, MazeRunner.Direction.East), Is.EqualTo(new Point(2, 1))); //South---------------------------------- Assert.That( () => MazeRunner.Move(mazePuzzle.Maze, currentPos, MazeRunner.Direction.South), Is.EqualTo(new Point(1, 2))); //West---------------------------------- Assert.That( () => MazeRunner.Move(mazePuzzle.Maze, currentPos, MazeRunner.Direction.West), Is.EqualTo(null)); }
private string[] moveToUnvisitedZones(GameState gameState, Zone currentZone, int[] unvisitedNeighbours) { var commands = new List <string>(); var zonesToVisit = unvisitedNeighbours.Count(); for (int i = 0; i < zonesToVisit - 1; i++) { if (Pods == 1) { //Log("Only one pod left in the squad. Sending it to last zone."); break; } var podsInGroup = (int)Math.Ceiling(Pods / (double)(zonesToVisit - i)); var squad = new MazeRunner(podsInGroup, this.ZoneId); gameState.Squads.Add(squad); this.Pods -= podsInGroup; commands.Add(squad.MoveTo(unvisitedNeighbours[i])); if (gameState.Zones[squad.ZoneId].MazeVisitedCount == 0) { gameState.Zones[squad.ZoneId].MazeVisitedCount = 1; } } //We keep ourselves around for the last neighbour commands.Add(this.MoveTo(unvisitedNeighbours.Last())); if (gameState.Zones[this.ZoneId].MazeVisitedCount == 0) { gameState.Zones[this.ZoneId].MazeVisitedCount = 1; } return(commands.ToArray()); }
public static int Task2(string[] routingDiagram) { var mazeRunner = new MazeRunner(routingDiagram); mazeRunner.Run(); return(mazeRunner.Steps + 1); }
public void LostTest1() { string[] directions = new string[] { "N", "E", "E", "E", "E" }; MazeRunner test = new MazeRunner(); string result = test.mazeRunner(maze, directions); Assert.AreEqual("Lost", result, "Should return: 'Lost'"); }
public string SolveSecondPart() { var maze = dataProvider.GetData(); var mazeRunner = new MazeRunner(maze); var shortestTime = mazeRunner.ShortestTimeTo(maze.Target.X, maze.Target.Y); return(shortestTime.TimeWithTorch.ToString()); }
public void FinishTest3() { string[] directions = new string[] { "N", "N", "N", "N", "N", "E", "E", "E", "E", "E", "W", "W" }; MazeRunner test = new MazeRunner(); string result = test.mazeRunner(maze, directions); Assert.AreEqual("Finish", result, "Should return: 'Finish'"); }
public void DeadTest2() { string[] directions = new string[] { "N", "N", "N", "N", "N", "E", "E", "S", "S", "S", "S", "S", "S" }; MazeRunner test = new MazeRunner(); string result = test.mazeRunner(maze, directions); Assert.AreEqual("Dead", result, "Should return: 'Dead'"); }
public void MazeRunner_Works() { var runner = new MazeRunner("day19testinput.txt"); var actual = runner.GetMazeLetterOrder(out int numSteps); Assert.Equal("ABCDEF", actual); Assert.Equal(38, numSteps); }
public void Test_MoveInAnyValidDirection() { var mazeFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestMazes\small_maze.txt"); var mazePuzzle = new MazePuzzle(mazeFilePath); var result = MazeRunner.MoveInAnyValidDirection(mazePuzzle.Maze, new Point(1, 1)); Assert.That(result, Is.EqualTo(new Point(2, 1))); }
public void Test_PrintMaze() { var mazeFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestMazes\small_maze.txt"); var mazePuzzle = new MazePuzzle(mazeFilePath); var escapeRoute = MazeRunner.SolveMaze(mazePuzzle.Maze, mazePuzzle.StartPoint, mazePuzzle.EndPoint); var strMaze = MazePrinter.PrintMaze(mazePuzzle.Maze, escapeRoute); Console.WriteLine(strMaze); }
public void Test_MoveInAnyValidDirection_Exception() { var mazeFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestMazes\small_maze.txt"); var mazePuzzle = new MazePuzzle(mazeFilePath); Assert.That( () => MazeRunner.MoveInAnyValidDirection(mazePuzzle.Maze, new Point(0, 0)), Throws.ArgumentException.With.Property("Message") .EqualTo("Current position {X=0,Y=0} is invalid for the current maze")); }
public static int GetAnswer2(string[] input) => FindAllKeysMultiMaze(input); // 2020 public static int FindAllKeys(string[] input) { var maze = new L1Maze(input); var l2Maze = new L2Maze(maze); var mazeRunner = new MazeRunner(l2Maze, l2Maze.StartPositions[0], 0); var allResults = BreadthFirstSearch(mazeRunner); return(allResults.First(t => t.HasAllKeys).MoveCount); }
void IPowerUpEvents.OnPowerUpCollected(PowerUp powerUp, MazeRunner player) { // We dont bother storing those that expire immediately if (!powerUp.expiresImmediately) { activePowerUps.Add(powerUp); UpdateActivePowerUpUi(); } uiText.text = powerUp.powerUpExplanation; uiSubtext.text = powerUp.powerUpQuote; uiTextDisplayTimer = uiTextDisplayDuration; }
public void Test_MarkCellAsVisited() { var mazeFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestMazes\small_maze.txt"); var mazePuzzle = new MazePuzzle(mazeFilePath); Assert.That( () => MazeRunner.MarkCellAsVisited(mazePuzzle.Maze, new Point(0, 0)), Throws.ArgumentException.With.Property("Message").EqualTo("Impossible to visit a wall")); Assert.That(mazePuzzle.Maze[1, 1], Is.EqualTo(0)); MazeRunner.MarkCellAsVisited(mazePuzzle.Maze, new Point(1, 1)); Assert.That(mazePuzzle.Maze[1, 1], Is.EqualTo(2)); }
public void Test_IsValidUnvisitedPosition_True() { var mazeFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestMazes\small_maze.txt"); var mazePuzzle = new MazePuzzle(mazeFilePath); //Empty Space------------------------- Assert.That( () => MazeRunner.IsUnvisitedPosition(mazePuzzle.Maze, new Point(1, 1)), Is.EqualTo(true)); Assert.That( () => MazeRunner.IsUnvisitedPosition(mazePuzzle.Maze, new Point(3, 4)), Is.EqualTo(true)); }
public void Test_SolveMaze_TrivialSolution() { var mazeFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestMazes\small_maze.txt"); var mazePuzzle = new MazePuzzle(mazeFilePath); var point = new Point(1, 1); var result = MazeRunner.SolveMaze(mazePuzzle.Maze, point, point); var expected = new List <Point>() { point, }; CollectionAssert.AreEqual(expected, result); }
public void Test_IsValidUnvisitedPosition_False() { var mazeFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestMazes\small_maze.txt"); var mazePuzzle = new MazePuzzle(mazeFilePath); //Negative Numbers------------------------- Assert.That( () => MazeRunner.IsUnvisitedPosition(mazePuzzle.Maze, new Point(-1, 3)), Is.EqualTo(false)); Assert.That( () => MazeRunner.IsUnvisitedPosition(mazePuzzle.Maze, new Point(3, -1)), Is.EqualTo(false)); Assert.That( () => MazeRunner.IsUnvisitedPosition(mazePuzzle.Maze, new Point(-5, -9)), Is.EqualTo(false)); //Large Numbers------------------------- Assert.That( () => MazeRunner.IsUnvisitedPosition(mazePuzzle.Maze, new Point(0, 6)), Is.EqualTo(false)); Assert.That( () => MazeRunner.IsUnvisitedPosition(mazePuzzle.Maze, new Point(5, 0)), Is.EqualTo(false)); Assert.That( () => MazeRunner.IsUnvisitedPosition(mazePuzzle.Maze, new Point(5, 6)), Is.EqualTo(false)); //Walls------------------------- Assert.That( () => MazeRunner.IsUnvisitedPosition(mazePuzzle.Maze, new Point(0, 0)), Is.EqualTo(false)); //Visited Cell------------------------- var visitedCell = new Point(3, 4); MazeRunner.MarkCellAsVisited(mazePuzzle.Maze, visitedCell); Assert.That(mazePuzzle.Maze[visitedCell.Y, visitedCell.X], Is.EqualTo(2)); Assert.That( () => MazeRunner.IsUnvisitedPosition(mazePuzzle.Maze, visitedCell), Is.EqualTo(false)); }
private void createRunner() { GameObject mazeRunnerObj = Instantiate(Resources.Load("Maze/Maze Runner")) as GameObject; mazeRunnerObj.transform.SetParent(transform); Vector3 chosenStart = (Vector3)validStartingSpots[rnd.Next(validStartingSpots.Count)]; mazeRunnerObj.transform.localScale = new Vector3(.15f, .15f); mazeRunner = mazeRunnerObj.AddComponent <MazeRunner>(); mazeRunner.setLocation(chosenStart); RectTransform mazeRunnerRect = mazeRunnerObj.GetComponent <RectTransform>(); BoxCollider2D runnerCollider = mazeRunnerObj.GetComponent <BoxCollider2D>(); runnerCollider.size = new Vector2(mazeRunnerRect.rect.width, mazeRunnerRect.rect.height); }
/// <summary> /// Finishes the loading objects we couldn't load until Player was loaded /// </summary> private void FinishLoadingObjects() { _boss = new MazeBoss( _bossTexture, new Vector2(0, 0), new Vector2(1100, 0), Player.TimeToLive < new TimeSpan(0, 1, 0) ? Player.TimeToLive : new TimeSpan(0, 1, 0), _conferenceRoomTexture); MazeRunnerOptions runnerOptions = new MazeRunnerOptions( _maze, Content.Load <Texture2D>(String.Format("Textures/Players/{0}/CloseupSmall", Player.CharacterName)), this._content.Load <SoundEffect>(Constants.SOFTPRODOLLAR_SOUND), this.ScreenManager.PointManager.GetValue(Constants.SOFTPRO_DOLLAR_VALUE)); _runner = new MazeRunner(this.ScreenManager.Game, runnerOptions); _contentFinishedLoading = true; }
public void Test_IsLegalPosition_True() { var mazeFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestMazes\small_maze.txt"); var mazePuzzle = new MazePuzzle(mazeFilePath); //Unvisited empty cells are legal cell positions. Assert.That(mazePuzzle.Maze[1, 1], Is.EqualTo(0)); Assert.That( () => MazeRunner.IsLegalPosition(mazePuzzle.Maze, new Point(1, 1)), Is.EqualTo(true)); MazeRunner.MarkCellAsVisited(mazePuzzle.Maze, new Point(1, 1)); Assert.That(mazePuzzle.Maze[1, 1], Is.EqualTo(2)); //Visited Cells are legal cell positions. Assert.That( () => MazeRunner.IsLegalPosition(mazePuzzle.Maze, new Point(1, 1)), Is.EqualTo(true)); }
public override void AfterMove(GameState gameState) { base.AfterMove(gameState); if (_path != null && !_path.Any()) { Log("EdgeFinder at #{0} has no more moves.", ZoneId); if (isValidTarget(gameState, gameState.Zones[ZoneId])) { Log("EdgeFinder at #{0} has reached its target. Converting it to a MazeRunner.", ZoneId); var squad = new MazeRunner(this.Pods, this.ZoneId); gameState.Squads.Remove(this); gameState.Squads.Add(squad); } else { Log("... but EdgeFinder at #{0} is not at a valid target.", ZoneId); //TargetZone = null; //_path = null; } } }
public void Test_SolveMaze() { var mazeFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestMazes\small_maze.txt"); var mazePuzzle = new MazePuzzle(mazeFilePath); var startPoint = new Point(1, 1); var endPoint = new Point(3, 4); var result = MazeRunner.SolveMaze(mazePuzzle.Maze, startPoint, endPoint); var expected = new List <Point>() { startPoint, new Point(2, 1), new Point(3, 1), new Point(3, 2), new Point(3, 3), endPoint }; CollectionAssert.AreEqual(expected, result); }
protected virtual void PowerUpCollected(GameObject gameObjectCollectingPowerUp) { // We only care if we've been collected by the player if (gameObjectCollectingPowerUp.tag != "Player") { return; } // We only care if we've not been collected before if (powerUpState == PowerUpState.IsCollected || powerUpState == PowerUpState.IsExpiring) { return; } powerUpState = PowerUpState.IsCollected; // We must have been collected by a player, store handle to player for later use mazeRunner = gameObjectCollectingPowerUp.GetComponent <MazeRunner>(); // We move the power up game object to be under the player that collect it, this isn't essential for functionality // presented so far, but it is neater in the gameObject hierarchy gameObject.transform.parent = mazeRunner.gameObject.transform; gameObject.transform.position = mazeRunner.gameObject.transform.position; // Collection effects PowerUpEffects(); // Payload PowerUpPayload(); // Send message to any listeners foreach (GameObject go in EventSystemListeners.main.listeners) { ExecuteEvents.Execute <IPowerUpEvents>(go, null, (x, y) => x.OnPowerUpCollected(this, mazeRunner)); } // Now the power up visuals can go away spriteRenderer.enabled = false; }
public static IEnumerable <MazeRunner> BreadthFirstSearch(MazeRunner startTrack) { var tracks = new Heap <MazeRunner>(); tracks.Add(startTrack, startTrack.MoveCount); var visited = new HashSet <object>(); while (tracks.Any()) { var track = tracks.Pop(); if (!visited.Add(track)) { continue; } foreach (var nextTrack in track.Children()) { yield return(nextTrack); tracks.Add(nextTrack, nextTrack.MoveCount); } } }
protected override void SetupFields() { base.SetupFields(); MaximumLife = 600; AmountDeadByAge = 0; minDeadByAge = 2000; mapNumber = GetComponent <MazeBuilder>().MapNumber; agents = new MazeRunner[numberOfAgents]; MazeRunner temp = originalAgent.GetComponent <MazeRunner>(); inputNodes = 2 + temp.numberOfLasers + temp.memoriesToConsider * 2; for (int i = 0; i < hiddenNodes.Length; i++) { if (hiddenNodes[i] <= 0) { hiddenNodes[i] = outputNodes; } } agentsPerCollum = numberOfAgents / NumberOfCollums; }
void IPowerUpEvents.OnPowerUpExpired(PowerUp powerUp, MazeRunner player) { activePowerUps.Remove(powerUp); UpdateActivePowerUpUi(); }
void Awake() { instance = this; }
private void OnEnable() { script = (MazeRunner)target; previousLasers = script.numberOfLasers; }
public static string Task1(string[] routingDiagram) { var mazeRunner = new MazeRunner(routingDiagram); return(mazeRunner.Run()); }