Exemple #1
0
 private bool PerformRoutine(SimulationRobot robot, string[] routine)
 {
     foreach (var instruction in routine)
     {
         if (instruction == "R")
         {
             robot.TurnRight();
         }
         else if (instruction == "L")
         {
             robot.TurnLeft();
         }
         else
         {
             var distance = int.Parse(instruction);
             while (distance > 0)
             {
                 robot.StepForward();
                 if (robot.IsDead)
                 {
                     return(false);
                 }
                 distance--;
             }
         }
     }
     return(true);
 }
        public void TestTryRoutine(string layout, string main, string a, string b, string c)
        {
            var layoutRows = layout.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
            var robot      = new SimulationRobot(layoutRows);
            var routine    = new MovementRoutine(main, a, b, c);

            Assert.IsTrue(routine.TryMainRoutine(robot));
        }
        public void TestFindGreedyPath(string layout, string expectedPath)
        {
            var layoutRows = layout.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
            var robot      = new SimulationRobot(layoutRows);
            var path       = string.Join(',', robot.FindGreedyPath());

            Assert.AreEqual(expectedPath, path);
        }
Exemple #4
0
        //Works if the routine doesn't require changing patterns on a straight section i.e. covering R12L8 with R6 + 6L8
        protected override void SolvePartTwo()
        {
            var testrobot  = new SimulationRobot(scaffoldImageRows);
            var greedyPath = testrobot.FindGreedyPath();
            var routine    = FindValidMovementRoutine(greedyPath, new List <string> [0], new int[0]);
            var robot      = new ASCIIComputer(program);

            resultPartTwo = routine.UploadToASCIIComputer(robot);
        }
        public void TestFindValidRoutine(string layout)
        {
            var layoutRows = layout.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
            var robot      = new SimulationRobot(layoutRows);
            var path       = robot.FindGreedyPath();
            var routine    = Solver.FindValidMovementRoutine(path, new List <string> [0], new int[0]);

            Assert.IsTrue(routine.TryMainRoutine(robot));
        }
        public void TestGetImageStrings(string layout)
        {
            var layoutRows = layout.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
            var robot      = new SimulationRobot(layoutRows);
            var output     = robot.GetImageStrings();

            for (int i = 0; i < output.Length; i++)
            {
                Assert.AreEqual(layoutRows[i], output[i]);
            }
        }
Exemple #7
0
        public bool TryMainRoutine(SimulationRobot robot)
        {
            var routineIsValid    = true;
            var routineEnumerator = ((IEnumerable <MovementFunctionId>)main).GetEnumerator();

            while (routineEnumerator.MoveNext() && routineIsValid)
            {
                var currentRoutine = SelectRoutine(routineEnumerator.Current);
                routineIsValid = PerformRoutine(robot, currentRoutine);
            }
            return(routineIsValid && robot.HasVisitedAllScaffolds());
        }