コード例 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Test Input:");
            string grid = Console.ReadLine();

            string[] gridArr = grid.Split(" ");
            int      max_X   = int.Parse(gridArr[0]);
            int      max_Y   = int.Parse(gridArr[1]);

            StringBuilder builder = new StringBuilder();

            builder.AppendLine("Exptected Output: ");

            for (int k = 1; k <= 2; k++)
            {
                Position p1          = new Position(max_X, max_Y);
                string   position1   = Console.ReadLine();
                string   rotateList1 = Console.ReadLine();

                string[] pos1 = position1.Split(" ");
                p1.CurrentRotation = pos1[2];
                p1.X = int.Parse(pos1[0]);
                p1.Y = int.Parse(pos1[1]);
                Rover r1 = new Rover();
                r1.SetPosition(p1);
                r1.SetRotateList(rotateList1);
                r1.StartAction();
                Position finalPos = r1.GetPosition();
                string   result   = string.Format("{0} {1} {2}", finalPos.X, finalPos.Y, finalPos.CurrentRotation);
                builder.AppendLine(result);
            }
            Console.WriteLine(builder.ToString());
            Console.ReadKey();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: teajaysee/MarsRover
        static void Main(string[] args)
        {
            // notes
            // if try to move outside bounds of perimiter, it will move to the edge in that direction and not throw an error
            // default plateau size is 0,0 to infinity unless set

            var plateau = new Plateau();

            plateau.SetGridSize(40, 30);

            // this needed to handle multiple rovers
            var RoverController = new RoverController(plateau);

            var rover = new Rover(RoverController);

            rover.SetPosition(10, 10, "N");
            rover.Move("R1R3L2L1");

            Console.WriteLine(rover.ToString());

            // if uncommented this will throw excepton as robots crash
            // var rover2 = new Rover(RoverController);
            // rover2.SetPosition(10, 10, "N");
            // rover2.Move("R1R3L2L3");
            // Console.WriteLine(rover2.ToString());

            Console.ReadLine();
        }
コード例 #3
0
        public bool ConfirmPosition(int X, int Y, Char Z)
        {
            if (X >= CoordinateMap.GetLength(0) || Y >= CoordinateMap.GetLength(1))
            {
                return(false);
            }

            rover.SetPosition(GetGridCoordinate(X, Y), Z);

            return(true);
        }