예제 #1
0
        public void Part1MoveExample2()
        {
            const string map =
                @"#########
#G..G..G#
#.......#
#.......#
#G..E..G#
#.......#
#.......#
#G..G..G#
#########";

            GridCell[,] grid = GridOperations.ParseGrid(map);
            var gameState = GameState.Start(grid);

            grid = gameState.Grid;

            IsGoblin(0, grid, 1, 1);
            IsGoblin(1, grid, 4, 1);
            IsGoblin(2, grid, 7, 1);
            IsGoblin(3, grid, 1, 4);
            IsGoblin(4, grid, 7, 4);
            IsGoblin(5, grid, 1, 7);
            IsGoblin(6, grid, 4, 7);
            IsGoblin(7, grid, 7, 7);
            IsElf(0, grid, 4, 4);

            gameState = gameState.PlayRound().state;
            grid      = gameState.Grid;

            IsGoblin(0, grid, 2, 1);
            IsGoblin(1, grid, 4, 2);
            IsGoblin(2, grid, 6, 1);
            IsGoblin(3, grid, 2, 4);
            IsGoblin(4, grid, 7, 3);
            IsGoblin(5, grid, 1, 6);
            IsGoblin(6, grid, 4, 6);
            IsGoblin(7, grid, 7, 6);
            IsElf(0, grid, 4, 3);

            gameState = gameState.PlayRound().state;
            grid      = gameState.Grid;

            IsGoblin(0, grid, 3, 1);
            IsGoblin(1, grid, 4, 2);
            IsGoblin(2, grid, 5, 1);
            IsGoblin(3, grid, 2, 3);
            IsGoblin(4, grid, 6, 3);
            IsGoblin(5, grid, 1, 5);
            IsGoblin(6, grid, 4, 5);
            IsGoblin(7, grid, 7, 5);
            IsElf(0, grid, 4, 3);

            gameState = gameState.PlayRound().state;
            grid      = gameState.Grid;

            IsGoblin(0, grid, 3, 2);
            IsGoblin(1, grid, 4, 2);
            IsGoblin(2, grid, 5, 2);
            IsGoblin(3, grid, 3, 3);
            IsGoblin(4, grid, 5, 3);
            IsGoblin(5, grid, 1, 4);
            IsGoblin(6, grid, 4, 4);
            IsGoblin(7, grid, 7, 5);
            IsElf(0, grid, 4, 3);

            gameState = gameState.PlayRound().state;
            grid      = gameState.Grid;

            IsGoblin(0, grid, 3, 2);
            IsGoblin(1, grid, 4, 2);
            IsGoblin(2, grid, 5, 2);
            IsGoblin(3, grid, 3, 3);
            IsGoblin(4, grid, 5, 3);
            IsGoblin(5, grid, 1, 4);
            IsGoblin(6, grid, 4, 4);
            IsGoblin(7, grid, 7, 5);
            IsElf(0, grid, 4, 3);
        }
예제 #2
0
        public void Part1PlayExample()
        {
            const string map =
                @"#######
#.G...#
#...EG#
#.#.#G#
#..G#E#
#.....#
#######";
            var state = GameState.Start(GridOperations.ParseGrid(map));

            Assert.AreEqual(200, state.GoblinHitPoints[0]);
            Assert.AreEqual(200, state.GoblinHitPoints[1]);
            Assert.AreEqual(200, state.GoblinHitPoints[2]);
            Assert.AreEqual(200, state.GoblinHitPoints[3]);
            Assert.AreEqual(200, state.ElfHitPoints[0]);
            Assert.AreEqual(200, state.ElfHitPoints[1]);

            // Round 1
            state = state.PlayRound().state;
            var grid = state.Grid;

            IsGoblin(0, grid, 3, 1);
            IsGoblin(1, grid, 5, 2);
            IsGoblin(2, grid, 5, 3);
            IsGoblin(3, grid, 3, 3);
            IsElf(0, grid, 4, 2);
            IsElf(1, grid, 5, 4);
            Assert.AreEqual(200, state.GoblinHitPoints[0]);
            Assert.AreEqual(197, state.GoblinHitPoints[1]);
            Assert.AreEqual(197, state.GoblinHitPoints[2]);
            Assert.AreEqual(200, state.GoblinHitPoints[3]);
            Assert.AreEqual(197, state.ElfHitPoints[0]);
            Assert.AreEqual(197, state.ElfHitPoints[1]);

            // Round 2
            state = state.PlayRound().state;
            grid  = state.Grid;

            IsGoblin(0, grid, 4, 1);
            IsGoblin(1, grid, 5, 2);
            IsGoblin(2, grid, 5, 3);
            IsGoblin(3, grid, 3, 2);
            IsElf(0, grid, 4, 2);
            IsElf(1, grid, 5, 4);
            Assert.AreEqual(200, state.GoblinHitPoints[0]);
            Assert.AreEqual(194, state.GoblinHitPoints[1]);
            Assert.AreEqual(194, state.GoblinHitPoints[2]);
            Assert.AreEqual(200, state.GoblinHitPoints[3]);
            Assert.AreEqual(188, state.ElfHitPoints[0]);
            Assert.AreEqual(194, state.ElfHitPoints[1]);

            for (int i = 0; i < 21; ++i)
            {
                state = state.PlayRound().state;
                grid  = state.Grid;

                IsGoblin(0, grid, 4, 1);
                IsGoblin(1, grid, 5, 2);
                IsGoblin(2, grid, 5, 3);
                IsGoblin(3, grid, 3, 2);
                IsElf(1, grid, 5, 4);
                if (i < 20)
                {
                    IsElf(0, grid, 4, 2);
                }
                else
                {
                    Assert.IsFalse(grid[2, 4].IsElf);
                }
            }
            Assert.AreEqual(200, state.GoblinHitPoints[0]);
            Assert.AreEqual(131, state.GoblinHitPoints[1]);
            Assert.AreEqual(131, state.GoblinHitPoints[2]);
            Assert.AreEqual(200, state.GoblinHitPoints[3]);
            Assert.AreEqual(-1, state.ElfHitPoints[0]);
            Assert.AreEqual(131, state.ElfHitPoints[1]);

            // Round 24
            state = state.PlayRound().state;
            grid  = state.Grid;

            IsGoblin(0, grid, 3, 1);
            IsGoblin(1, grid, 4, 2);
            IsGoblin(2, grid, 5, 3);
            IsGoblin(3, grid, 3, 3);
            IsElf(1, grid, 5, 4);
            Assert.AreEqual(200, state.GoblinHitPoints[0]);
            Assert.AreEqual(131, state.GoblinHitPoints[1]);
            Assert.AreEqual(128, state.GoblinHitPoints[2]);
            Assert.AreEqual(200, state.GoblinHitPoints[3]);
            Assert.AreEqual(128, state.ElfHitPoints[1]);

            // Round 25
            state = state.PlayRound().state;
            grid  = state.Grid;

            IsGoblin(0, grid, 2, 1);
            IsGoblin(1, grid, 3, 2);
            IsGoblin(2, grid, 5, 3);
            IsGoblin(3, grid, 3, 4);
            IsElf(1, grid, 5, 4);
            Assert.AreEqual(200, state.GoblinHitPoints[0]);
            Assert.AreEqual(131, state.GoblinHitPoints[1]);
            Assert.AreEqual(125, state.GoblinHitPoints[2]);
            Assert.AreEqual(200, state.GoblinHitPoints[3]);
            Assert.AreEqual(125, state.ElfHitPoints[1]);

            // Round 26
            state = state.PlayRound().state;
            grid  = state.Grid;

            IsGoblin(0, grid, 1, 1);
            IsGoblin(1, grid, 2, 2);
            IsGoblin(2, grid, 5, 3);
            IsGoblin(3, grid, 3, 5);
            IsElf(1, grid, 5, 4);
            Assert.AreEqual(200, state.GoblinHitPoints[0]);
            Assert.AreEqual(131, state.GoblinHitPoints[1]);
            Assert.AreEqual(122, state.GoblinHitPoints[2]);
            Assert.AreEqual(200, state.GoblinHitPoints[3]);
            Assert.AreEqual(122, state.ElfHitPoints[1]);

            // Round 27
            state = state.PlayRound().state;
            grid  = state.Grid;

            IsGoblin(0, grid, 1, 1);
            IsGoblin(1, grid, 2, 2);
            IsGoblin(2, grid, 5, 3);
            IsGoblin(3, grid, 4, 5);
            IsElf(1, grid, 5, 4);
            Assert.AreEqual(200, state.GoblinHitPoints[0]);
            Assert.AreEqual(131, state.GoblinHitPoints[1]);
            Assert.AreEqual(119, state.GoblinHitPoints[2]);
            Assert.AreEqual(200, state.GoblinHitPoints[3]);
            Assert.AreEqual(119, state.ElfHitPoints[1]);

            // Round 28
            state = state.PlayRound().state;
            grid  = state.Grid;

            IsGoblin(0, grid, 1, 1);
            IsGoblin(1, grid, 2, 2);
            IsGoblin(2, grid, 5, 3);
            IsGoblin(3, grid, 5, 5);
            IsElf(1, grid, 5, 4);
            Assert.AreEqual(200, state.GoblinHitPoints[0]);
            Assert.AreEqual(131, state.GoblinHitPoints[1]);
            Assert.AreEqual(116, state.GoblinHitPoints[2]);
            Assert.AreEqual(200, state.GoblinHitPoints[3]);
            Assert.AreEqual(113, state.ElfHitPoints[1]);

            // Round 29-47
            for (int i = 0; i < 19; ++i)
            {
                state = state.PlayRound().state;
                grid  = state.Grid;

                IsGoblin(0, grid, 1, 1);
                IsGoblin(1, grid, 2, 2);
                IsGoblin(2, grid, 5, 3);
                IsGoblin(3, grid, 5, 5);
                if (i < 18)
                {
                    IsElf(1, grid, 5, 4);
                }
                else
                {
                    Assert.IsFalse(grid[5, 4].IsElf);
                }
            }
            Assert.AreEqual(200, state.GoblinHitPoints[0]);
            Assert.AreEqual(131, state.GoblinHitPoints[1]);
            Assert.AreEqual(59, state.GoblinHitPoints[2]);
            Assert.AreEqual(200, state.GoblinHitPoints[3]);
            Assert.AreEqual(-1, state.ElfHitPoints[1]);
        }