示例#1
0
        static void Main(string[] args)
        {
            var fileText  = File.ReadAllLines(@"Datasets\day20.txt");
            var screen    = fileText.Select(x => x.ToCharArray()).ToArray();
            var labyrinth = new Labyrinth(screen);

            labyrinth.Print();
            labyrinth.FindObjects();
            labyrinth.CalculateReachableKeysAndDoors();
        }
示例#2
0
        static void Main(string[] args)
        {
            var fileText  = File.ReadAllLines(@"Datasets\day18.txt");
            var screen    = fileText.Select(x => x.ToCharArray()).ToArray();
            var labyrinth = new Labyrinth(screen);
            //labyrinth.Print();
            var result         = 0;
            var allDoorsOpened = false;

            //while (!allDoorsOpened)
            //{
            labyrinth.FindObjects();
            labyrinth.CalculateReachableKeysAndDoors();
            var dict          = new Dictionary <Point, int>();
            var keyDictionary = new Dictionary <char, List <Point> >();

            foreach (var rKey in labyrinth.Keys)
            {
                Console.WriteLine($"Key: {rKey.Name}");
                var area = labyrinth.Area.Clone() as char[][];
                var lab  = new Labyrinth(area);
                var ent  = new Point('@', lab.Entrance.X, lab.Entrance.Y);
                lab.MoveEntrance(rKey);
                lab.FindObjects();
                lab.Print();
                lab.CalculateReachableKeysAndDoors();
                lab.MoveEntrance(ent);
                lab.Area[rKey.Y][rKey.X] = rKey.Name;
                var distance = lab.GetClosestKeyDistance();
                dict.Add(rKey, distance);
                keyDictionary.Add(rKey.Name, lab.ReachableKeys.Keys.ToList());
            }
            //result += dict.OrderBy(x => x.Value).First().Value;
            //var key = dict.OrderBy(x => x.Value).First().Key;
            //labyrinth.OpenDoor(key);

            labyrinth.Print();
            //    if (labyrinth.Doors.Count == 0 && labyrinth.Keys.Count == 0) allDoorsOpened = true;
            //}

            Console.WriteLine($"Distance: {result}");
        }