Пример #1
0
        public void Part1MoveExample1()
        {
            const string map =
                @"#######
#.E...#
#.....#
#...G.#
#######";

            var gridPair = GridPair.For(GridOperations.ParseGrid(map));

            GridOperations.CalculateCloseness(gridPair);
            GridCell[,] grid = gridPair.Primary;

            var p = GridOperations.CalculateMove(grid, 2, 1);

            Assert.AreEqual((1, 0), p);
        }
Пример #2
0
        public void NearestIsSelectedInReadingOrder()
        {
            // In the map below, we focus our attention on the square directly
            // belong the only Elf. This is adjacent to two cells in range of
            // two different Goblins. So the distance to each Goblin is 2, meaning
            // there is a tie in the 'nearest' ranking. The rules state that such
            // ties must be broken by using reading order. The Goblin on the 2nd
            // line comes before the one on the 3rd line, so we must check that
            // this is the reported one. (Without taking special steps, it won't
            // be. We populate the closeness map by growing out one step at a time
            // from each Goblin (and from each Elf), meaning that after 1 pass,
            // the 3rd line will look like this:
            //   #.1.1G#
            // with that first 1 denoting a distance of 1 to the Goblin directly
            // beneath it (Goblin 1) and the second denoting a distance of 1 to
            // the Goblin to the right (Goblin 0). Since each pass works through
            // the grid in reading order, we'll see that first 1 before we see
            // the second,
            const string map =
                @"#######
#..E..#
#....G#
#.G...#
#.....#
#######";
            var gridPair = GridPair.For(GridOperations.ParseGrid(map));

            GridOperations.CalculateCloseness(gridPair);
            GridCell[,] grid = gridPair.Primary;

            Assert.AreEqual(0, grid[2, 5].GoblinId, "Test setup error");

            GridCell testCell = grid[1, 3];

            Assert.AreEqual(3, testCell.DistanceToGoblinInRange);
            Assert.AreEqual(0, testCell.GoblinId);
            Assert.AreEqual((5, 1), testCell.GoblinInRangePosition);
        }