Exemple #1
0
        public void GetShortestPathToCollectAllKeysWithQuadRobotsTest()
        {
            // Test examples taken from here:
            //https://adventofcode.com/2019/day/18
            var testData = new List <Tuple <string[], int> >(new Tuple <string[], int>[] {
                // #######       #######
                // #a.#Cd#       #a.#Cd#
                // ##...##       ##@#@##
                // ##.@.##  -->  #######
                // ##...##       ##@#@##
                // #cB#Ab#       #cB#Ab#
                // #######       #######
                new Tuple <string[], int>(
                    new string[]
                {
                    "#######",
                    "#a.#Cd#",
                    "##...##",
                    "##.@.##",
                    "##...##",
                    "#cB#Ab#",
                    "#######"
                }, 8),

                // 24 steps:
                // ###############
                // #d.ABC.#.....a#
                // ######...######
                // ######.@.######
                // ######...######
                // #b.....#.....c#
                // ###############
                new Tuple <string[], int>(
                    new string[]
                {
                    "###############",
                    "#d.ABC.#.....a#",
                    "######...######",
                    "######.@.######",
                    "######...######",
                    "#b.....#.....c#",
                    "###############"
                }, 24),

                // 32 steps:
                // #############
                // #DcBa.#.GhKl#
                // #.###...#I###
                // #e#d#.@.#j#k#
                // ###C#...###J#
                // #fEbA.#.FgHi#
                // #############
                new Tuple <string[], int>(
                    new string[]
                {
                    "#############",
                    "#DcBa.#.GhKl#",
                    "#.###...#I###",
                    "#e#d#.@.#j#k#",
                    "###C#...###J#",
                    "#fEbA.#.FgHi#",
                    "#############"
                }, 32),

                // 72 steps:
                // #############
                // #g#f.D#..h#l#
                // #F###e#E###.#
                // #dCba...BcIJ#
                // #####.@.#####
                // #nK.L...G...#
                // #M###N#H###.#
                // #o#m..#i#jk.#
                // #############
                new Tuple <string[], int>(
                    new string[]
                {
                    "#############",
                    "#g#f.D#..h#l#",
                    "#F###e#E###.#",
                    "#dCba...BcIJ#",
                    "#####.@.#####",
                    "#nK.L...G...#",
                    "#M###N#H###.#",
                    "#o#m..#i#jk.#",
                    "#############"
                }, 72),
            });

            foreach (var testExample in testData)
            {
                var maze   = new Maze(testExample.Item1, true);
                var result = Day18.GetShortestPathToCollectAllKeys(maze);
                Assert.Equal(testExample.Item2, result.TotalPathCost);
            }
        }
Exemple #2
0
        public void GetShortestPathToCollectAllKeysTest()
        {
            // Test examples taken from here:
            //https://adventofcode.com/2019/day/18
            var testData = new List <Tuple <string[], int> >(new Tuple <string[], int>[] {
                // Collecting every key took a total of 8 steps:
                // #########
                // #[email protected]#
                // #########
                new Tuple <string[], int>(
                    new string[]
                {
                    "#########",
                    "#[email protected]#",
                    "#########"
                }, 8),

                // 86 steps:
                // ########################
                // #[email protected].#
                // ######################.#
                // #d.....................#
                // ########################
                new Tuple <string[], int>(
                    new string[]
                {
                    "########################",
                    "#[email protected].#",
                    "######################.#",
                    "#d.....................#",
                    "########################"
                }, 86),

                // 132 steps:
                // ########################
                // #...............b.C.D.f#
                // #.######################
                // #[email protected]#
                // ########################
                new Tuple <string[], int>(
                    new string[]
                {
                    "########################",
                    "#...............b.C.D.f#",
                    "#.######################",
                    "#[email protected]#",
                    "########################"
                }, 132),

                // 136 steps:
                // #################
                // #i.G..c...e..H.p#
                // ########.########
                // #j.A..b...f..D.o#
                // ########@########
                // #k.E..a...g..B.n#
                // ########.########
                // #l.F..d...h..C.m#
                // #################
                new Tuple <string[], int>(
                    new string[]
                {
                    "#################",
                    "#i.G..c...e..H.p#",
                    "########.########",
                    "#j.A..b...f..D.o#",
                    "########@########",
                    "#k.E..a...g..B.n#",
                    "########.########",
                    "#l.F..d...h..C.m#",
                    "#################"
                }, 136),

                // 81 steps:
                // ########################
                // #@..............ac.GI.b#
                // ###d#e#f################
                // ###A#B#C################
                // ###g#h#i################
                // ########################
                new Tuple <string[], int>(
                    new string[]
                {
                    "########################",
                    "#@..............ac.GI.b#",
                    "###d#e#f################",
                    "###A#B#C################",
                    "###g#h#i################",
                    "########################"
                }, 81),
            });

            foreach (var testExample in testData)
            {
                var maze   = new Maze(testExample.Item1);
                var result = Day18.GetShortestPathToCollectAllKeys(maze);
                Assert.Equal(testExample.Item2, result.TotalPathCost);
            }
        }