Beispiel #1
0
 public LowLevelRobot(LowLevelMap map, int x, int y)
 {
     mMap = map;
     X    = mRealX = x;
     Y    = mRealY = y;
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            GraphViewer gv;
            string      graph1 = "...........\n" +
                                 ".OOOOOOOOO.\n" +
                                 ".O...O...O.\n" +
                                 ".OOOOOOOOO.\n" +
                                 ".O...O...O.\n" +
                                 ".OOOOOOOOO.\n" +
                                 "...........";

            string graph2 = ".......\n" +
                            ".O...O.\n" +
                            ".O...O.\n" +
                            ".OOOOO.\n" +
                            "...O...\n" +
                            "...O...\n" +
                            ".......\n";

            string graph3 = "...........\n" +
                            ".OOOOOOOOO.\n" +
                            ".O...O...O.\n" +
                            ".O...O...O.\n" +
                            ".O...O...O.\n" +
                            ".....O.....\n" +
                            ".....O.....\n" +
                            ".....O.....\n" +
                            ".OOOOOOOOO.\n" +
                            "...........\n";

            string graph4 = ".........................\n" +
                            ".O...OOOOOOOOOOOOOOO...O.\n" +
                            ".O.......O.....O.......O.\n" +
                            ".O.......O.....O.......O.\n" +
                            ".O.......O.....O.......O.\n" +
                            ".O.......O.....O.......O.\n" +
                            ".OOOOOOOOO.....OOOOOOOOO.\n" +
                            ".....O.............O.....\n" +
                            ".....O......O......O.....\n" +
                            ".....O......O......O.....\n" +
                            ".....O......O......O.....\n" +
                            ".OOOOOOOOOOOOOOOOOOOOOOO.\n" +
                            ".........................\n";

            string graph5 = "...........................\n" +
                            ".OOOOOOOOOOOOOOOOOOOOOOOOO.\n" +
                            ".O.....O.....O.....O.....O.\n" +
                            ".O.....O.....O.....O.....O.\n" +
                            ".OOOOOOOOOOOOOOOOOOOOOOOOO.\n" +
                            ".O.....O.....O.....O.....O.\n" +
                            ".O.....O.....O.....O.....O.\n" +
                            ".OOOOOOOOOOOOOOOOOOOOOOOOO.\n" +
                            ".O.....O.....O.....O.....O.\n" +
                            ".O.....O.....O.....O.....O.\n" +
                            ".OOOOOOOOOOOOOOOOOOOOOOOOO.\n" +
                            ".O.....O.....O.....O.....O.\n" +
                            ".O.....O.....O.....O.....O.\n" +
                            ".OOOOOOOOOOOOOOOOOOOOOOOOO.\n" +
                            "...........................\n";

            lowMap   = new LowLevelMap('O', '.', graph4);
            lowRobot = new LowLevelRobot(lowMap, 1, 1);

            MapNode firstNode = ExploreMap(lowRobot.CheckNode(), null, 0, null);
            double  distToSecond;

            Console.WriteLine("[DFS 결과]");
            Console.WriteLine($"Node 수 : {nodeList.Count}");
            foreach (var ele in nodeList)
            {
                Console.WriteLine($"{ele.NodeNumber} : ({ele.Position}), ({ele.Error})");
            }

            gv = new GraphViewer();
            gv.AddPoints(firstNode);
            gv.Show();

            Direction secondDir = firstNode.FindDirOf(nodeList[1]).Value;

            TurnRobot(secondDir);
            distToSecond = firstNode.GetDist(secondDir);

            lowRobot.Move(1);

            robotPos.Node1     = firstNode;
            robotPos.Node2     = nodeList[1];
            robotPos.DivRatio1 = 1;
            robotPos.DivRatio2 = distToSecond - 1;

            Console.Write("최단 거리를 탐색할 위치를 입력하세요. (입력형식: {node1} {node2} {ratio1} {ratio2}) : ");
            string[] token = Console.ReadLine().Split();

            MapPosition dest = new MapPosition();

            dest.Node1     = nodeList[int.Parse(token[0])];
            dest.Node2     = nodeList[int.Parse(token[1])];
            dest.DivRatio1 = double.Parse(token[2]);
            dest.DivRatio2 = double.Parse(token[3]);

            Queue <Command> commands = new Queue <Command>();
            double          dist;

            FindShortestRoute(dest, commands, out dist);

            Console.WriteLine($"최단 거리: {dist}");
            while (commands.Count > 0)
            {
                Console.WriteLine(commands.Dequeue().ToString());
            }

            Console.WriteLine("아무키나 누르면 디버그를 종료합니다...");
            Console.ReadKey(true);
        }