Esempio n. 1
0
 public static void DrawMaze(Maze maze, Robot robot, Robot2 robot2, Robot3 robot3)
 {
     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("1");
     Console.SetCursorPosition(robot2.Location.X, robot2.Location.Y);
     Console.Write("2");
     Console.SetCursorPosition(robot3.Location.X, robot3.Location.Y);
     Console.Write("3");
 }
Esempio n. 2
0
        public bool MakeStep2()
        {
            //достигли выхода?
            if (Maze[Robot2.Location] == Cell.Exit)
            {
                return(false);
            }
            //получаем значение ячейки справа
            var left = Maze[Robot2.Location + Robot2.Direction.Rotate(1)];
            //получаем значение ячейки слева
            var right  = Maze[Robot2.Location + Robot2.Direction.Rotate(-1)];
            var center = Maze[Robot2.Location + Robot2.Direction];
            // //если справа нет стены - поворачиваем направо
            // if (left != Cell.Wall)
            //     Robot2.Direction = Robot2.Direction.Rotate(1);
            // else if (right != Cell.Wall)
            //     Robot2.Direction = Robot2.Direction.Rotate(-1);
            // else
            //     //пока впереди есть стена - поворачиваем налево
            //
            //tdgnsdil;tkgn
            Random rnd   = new Random();
            int    value = rnd.Next(1, 3);

            if (right == Cell.Wall && left == Cell.Wall && center == Cell.Wall)
            {
                Robot2.Direction = Robot2.Direction.Rotate(-1);
                Robot2.Direction = Robot2.Direction.Rotate(-1);
            }

            else if (right != Cell.Wall && left != Cell.Wall)
            {
                if (value == 1)
                {
                    Robot2.Direction = Robot2.Direction.Rotate(-1);
                }
                else
                {
                    Robot2.Direction = Robot2.Direction.Rotate(1);
                }
            }
            //dbjknjkgnjn;dgdl
            else if (right != Cell.Wall && center != Cell.Wall)
            {
                if (value == 1)
                {
                    Robot2.Direction = Robot2.Direction.Rotate(-1);
                }
            }
            //jl;t;tnjktgnj;stotdnxjlbk
            else if (center != Cell.Wall && left != Cell.Wall)
            {
                if (value == 1)
                {
                    Robot2.Direction = Robot2.Direction.Rotate(1);
                }
            }
            else if (right != Cell.Wall)
            {
                Robot2.Direction = Robot2.Direction.Rotate(-1);
            }
            else if (left != Cell.Wall)
            {
                Robot2.Direction = Robot2.Direction.Rotate(1);
            }

            // if (Maze[Robot2.Location + Robot2.Direction] != Cell.Wall)
            //     Robot2.GoForward();
            // else if (right == Cell.Wall)
            //     Robot2.Direction = Robot2.Direction.Rotate(1);
            // else if (left  == Cell.Wall)
            //     Robot2.Direction = Robot2.Direction.Rotate(-1);
            // else if (center == Cell.Wall)
            //     Robot2.Direction = Robot2.Direction.Rotate(-1);
            Robot2.GoForward();

            return(true);
        }