Пример #1
0
        /// <summary>
        /// Execution function for Day 15
        /// </summary>
        public void Execute15()
        {
            UserActionAsync(() =>
            {
                WriteToConsole("Start execution of Day15");
                var parser       = GetInputParser("Day15Input.txt");
                var originalCode = parser.GetIntCode();
                var code         = originalCode.ToList();

                var droid = new RepairDroid(code);
                droid.Explore();

                var route = droid.GetShortestRoute(new IntVector(0, 0), droid.OxygenSystem);

                var map = droid.GetRouteMap(route);

                RunInUiThread(() =>
                {
                    var dialog = new ImageDisplay(map);
                    dialog.Show();
                });

                WriteToConsole($"The droid needed {route.Count - 1} movement commands to locate the oxygen system");

                var time = droid.GetOxygenSpreadingTime(droid.OxygenSystem);

                WriteToConsole($"It takes {time} minutes until the area is filled with oxygen");
            });
        }
    public Droid CreateDroid(DroidType type)
    {
        if (type == DroidType.SearchDroid)
        {
            Droid droid = new SearchDroid();
            droid.SetItemType(ItemType.Droid);
            droid.SetItemName("Search Droid");
            droid.GetDroidModel().GetDroidView().SetDroidSprite(gatherDroidImage);
            droid.AddItemImage(gatherDroidImage);
            droid.SetStackable(1);

            return(droid);
        }

        if (type == DroidType.RepairDroid)
        {
            Droid droid = new RepairDroid();
            droid.SetItemType(ItemType.Droid);
            droid.SetItemName("Repair droid");
            droid.GetDroidModel().GetDroidView().SetDroidSprite(repairDroidImage);
            droid.AddItemImage(repairDroidImage);
            droid.SetStackable(1);

            return(droid);
        }
        return(null);
    }
Пример #3
0
    private void Move(Direction direction)
    {
        Compiler.Clear();
        Compiler.SetInputs((long)direction);
        Program = Compiler.Compute(Program);
        var output      = Compiler.OutputValue;
        var forwardTile = GetForward(CurrentPosition, direction);

        ExploredMap[forwardTile.y, forwardTile.x] = true;
        if (output == 0)
        {
            Map[forwardTile.y, forwardTile.x] = TileType.Wall;
        }
        else if (output == 1)
        {
            Map[forwardTile.y, forwardTile.x] = TileType.Empty;
            CurrentPosition = forwardTile;
        }
        else
        {
            Map[forwardTile.y, forwardTile.x] = TileType.OxygenSystem;
            CurrentPosition = forwardTile;
        }

        var map = (TileType[, ])Map.Clone();

        AOCExecutor.ActionForMainOnPerUpdate.Enqueue(() => RepairDroid.MapToTexturee(map, AOCUI.Instance.Part1ComputeOutput));
    }
Пример #4
0
    public static int Part1(string inputText)
    {
        var program = new IntCodeProgram(InputParser.ListOfLongs(inputText, ','), 0, 0);
        var robot   = new RepairDroid(program);

        robot.FindOxygenSystem();
        return(1);
    }
Пример #5
0
        public void Test_DayFifteen_PartTwo()
        {
            var source = Path.Combine(TestHelper.TestDir, "Day15.Input.txt");
            //< Instantiate droid (will fill out the Maze)
            var droid = new RepairDroid(source);
            //< Get that puzzle result boi
            var time = droid.GetTimeToFill();

            Assert.IsTrue(time == 302);
        }
Пример #6
0
        public void Test_DayFifteen_PartOne()
        {
            var source = Path.Combine(TestHelper.TestDir, "Day15.Input.txt");
            //< Instantiate droid (will fill out the Maze)
            var droid = new RepairDroid(source); //< Confirmed droid I'm looking for
            //< Get that puzzle result
            var steps = droid.GetMinStepsToOxygen();

            //< Ensure we ain't f**k up
            Assert.IsTrue(steps == 296);
        }
Пример #7
0
        public void MoveTest(long command, TileType expectedTileType, int expectedX, int expectedY)
        {
            var program = File.ReadAllText("Input.txt");

            var droid = new RepairDroid(program);

            var droidAfterMove = droid.Move((MovementCommand)command);

            Assert.Equal(expectedTileType, droidAfterMove.TileType);
            Assert.Equal((expectedX, expectedY), droidAfterMove.Position);
            Assert.Equal(1, droidAfterMove.MoveCounter);
        }
Пример #8
0
        public string SolvePartOne(string[] input)
        {
            long[] program = string.Join(",", input)
                             .Split(",")
                             .Select(x => Int64.Parse(x))
                             .ToArray();

            RepairDroid droid = new RepairDroid(program);
            Dictionary <Point, long> tankMap   = droid.MapOxygenTank();
            Dictionary <Point, int>  distances = FillWithOxygen(tankMap);

            return(distances[new Point(0, 0)].ToString());
        }
Пример #9
0
    public Droid CreateDroid(DroidType type)
    {
        if (type == DroidType.SearchDroid)
        {
            Droid droid = new SearchDroid();
            droid.GetDroidModel().GetDroidView().SetDroidSprite(gatherDroidImage);

            return(droid);
        }

        if (type == DroidType.RepairDroid)
        {
            Droid droid = new RepairDroid();
            droid.GetDroidModel().GetDroidView().SetDroidSprite(repairDroidImage);

            return(droid);
        }

        return(null);
    }