Beispiel #1
0
        private static void DrawMaze(Maze maze, Robot robot, Robotas robotas)
        {
            Console.Clear();
            for (int row = 0; row < maze.Height; row++)
            {
                for (int col = 0; col < maze.Width; col++)
                {
                    switch (maze[col, row])
                    {
                    case Cell.Wall: Console.Write('#'); break;

                    case Cell.Exit: Console.Write('E'); break;

                    default: Console.Write(' '); break;
                    }
                }
                Console.WriteLine();
            }
            Console.SetCursorPosition(robot.Location.X, robot.Location.Y);
            Console.Write("*");
            Console.SetCursorPosition(robotas.Location.X, robotas.Location.Y);
            Console.Write("*");
        }
Beispiel #2
0
        private static void Main(string[] args)
        {
            Console.Write("Robot's X: ");
            var x = int.Parse(Console.ReadLine());

            Console.Write("Robot's Y: ");
            var y = int.Parse(Console.ReadLine());

            var robot = new Robot {
                Location = new Point {
                    X = x, Y = y
                }
            };
            var robotas = new Robotas {
                Location = new Point {
                    X = x + 3, Y = y + 2
                }
            };
            var maze = Maze.Load("c:\\1.txt");
            var ai   = new AI {
                Robot = robot, Maze = maze, Robotas = robotas
            };
            var a = true;
            var b = true;

            do
            {
                DrawMaze(maze, robot, robotas);
                Thread.Sleep(200);
                a = ai.MakeStep();
                b = ai.MakeStepas();
            } while (a || b);

            DrawMaze(maze, robot, robotas);

            Console.ReadKey();
        }