예제 #1
0
        public void TestUpdateTile()
        {
            Arcade a = new Arcade(new long[1]);
            Point  p = new Point(0, 4);

            a.UpdateTile(p, (int)Arcade.Tile.Wall);
            a.UpdateTile(p, (int)Arcade.Tile.Empty);

            Assert.That(a.Tiles.Count, Is.EqualTo(1));
            Assert.That(a.Tiles[p], Is.EqualTo(Arcade.Tile.Empty));
        }
예제 #2
0
        public void TestGetVisualRepresentation()
        {
            Arcade a = new Arcade(new long[1]);

            a.UpdateTile(new Point(0, 0), (int)Arcade.Tile.Empty);
            a.UpdateTile(new Point(1, 0), (int)Arcade.Tile.Wall);
            a.UpdateTile(new Point(2, 0), (int)Arcade.Tile.Block);
            a.UpdateTile(new Point(3, 0), (int)Arcade.Tile.HorizontalPaddle);
            a.UpdateTile(new Point(4, 0), (int)Arcade.Tile.Ball);

            Assert.That(a.GetVisualRepresentation(), Is.EqualTo(".+#~O\n"));
        }
예제 #3
0
        public void TestCountTilesOfType()
        {
            Arcade a = new Arcade(new long[1]);

            a.UpdateTile(new Point(0, 4), (int)Arcade.Tile.Wall);
            a.UpdateTile(new Point(1, 4), (int)Arcade.Tile.Wall);
            a.UpdateTile(new Point(2, 4), (int)Arcade.Tile.Wall);
            a.UpdateTile(new Point(3, 4), (int)Arcade.Tile.Empty);
            a.UpdateTile(new Point(4, 4), (int)Arcade.Tile.Empty);

            Assert.That(a.CountTilesOfType(Arcade.Tile.Wall), Is.EqualTo(3));
            Assert.That(a.CountTilesOfType(Arcade.Tile.Empty), Is.EqualTo(2));
            Assert.That(a.CountTilesOfType(Arcade.Tile.Ball), Is.EqualTo(0));
        }
예제 #4
0
        public string SolvePartOne(string[] input)
        {
            long[] game = string.Join(",", input)
                          .Split(",")
                          .Select(x => Int64.Parse(x))
                          .ToArray();
            Arcade arcade = new Arcade(game);

            Point p;
            int   tileId;

            do
            {
                p = new Point(0, 0);

                arcade.Run();
                p.X = (int)arcade.Output;

                arcade.Run();
                p.Y = (int)arcade.Output;

                arcade.Run();
                tileId = (int)arcade.Output;

                arcade.UpdateTile(p, tileId);
            } while (arcade.CurrentState != IntcodeComputer.State.Halted);

            return(arcade.CountTilesOfType(Arcade.Tile.Block).ToString());
        }
예제 #5
0
        public void TestUpdateMaxX()
        {
            Arcade a = new Arcade(new long[1]);
            Point  p = new Point(4, 0);

            a.UpdateTile(p, (int)Arcade.Tile.Wall);

            Assert.That(a.MaxX, Is.EqualTo(4));
        }
예제 #6
0
        public string SolvePartTwo(string[] input)
        {
            long[] game = string.Join(",", input)
                          .Split(",")
                          .Select(x => Int64.Parse(x))
                          .ToArray();

            game[0] = 2;

            Arcade arcade = new Arcade(game);

            arcade.Input = 0;

            int   score = 0;
            Point p;
            int   tileId;

            do
            {
                p = new Point(0, 0);

                arcade.Run();
                p.X = (int)arcade.Output;

                arcade.Run();
                p.Y = (int)arcade.Output;

                arcade.Run();
                tileId = (int)arcade.Output;

                if (-1 == p.X)
                {
                    score = tileId;
                }
                else
                {
                    arcade.UpdateTile(p, tileId);
                }

                // Console.Clear();
                // Console.WriteLine($"Score: {score}");
                // Console.WriteLine($"{arcade.GetVisualRepresentation()}");
            } while (arcade.CurrentState != IntcodeComputer.State.Halted);

            return(score.ToString());
        }