コード例 #1
0
        public override string ExecuteCommands(string commandsString, Robot robot)
        {
            foreach (var command in GetCommands(commandsString))
            {
                var queryBase=_store.GetAll().Where(x => x.WorldEdgePoint.Location.Point.X == robot.Location.Point.X &&
                                           x.WorldEdgePoint.Location.Direction == robot.Location.Direction &&
                                           x.WorldEdgePoint.Command.CommandInstruction == command.CommandInstruction);

              
                if(queryBase.Where(x => x.Key == "XMax").ToList().Any())
                    continue;

                if (queryBase.Where(x => x.Key == "YMax").ToList().Any())
                    continue;

                if (queryBase.Where(x => x.Key == "XMin").ToList().Any())
                    continue;

                if (queryBase.Where(x => x.Key == "YMin").ToList().Any())
                    continue;
                var currentLocation = robot.Location;              
                command.Execute(robot);
                var ret = RobotIsOnPlanet(robot);
                if (ret!=null)
                {
                    var worldEdge = new WorldEdgePoint() {Command = command, Location = currentLocation};
                    _store.Add(new WorldEdgeLine() { WorldEdgePoint = worldEdge,Key = ret});
                    return string.Format("{0} {1}", currentLocation, "LOST");
                }
            }

            return robot.Location.ToString();
        }
コード例 #2
0
        public string RobotIsOnPlanet(Robot robot)
        {
            if (robot.Location.Point.X > World.Point.X)
                return "XMax";
            if (robot.Location.Point.X < 0)
                return "XMin";
            if (robot.Location.Point.Y > World.Point.Y)
                return "YMax";
            if (robot.Location.Point.Y < 0)
                return "YMin";

            return null;

        }
コード例 #3
0
ファイル: RobotTests.cs プロジェクト: richinoz/Orchard1.6
        public void subsequent_robots_should_not_fall_off_planet_at_same_point()
        {
            var commandProcessorFactory = new CommandProcessorFactory();
            var commandProcessorRobotWorld = commandProcessorFactory.Build<CommandProcessorRobotWorldPoints>(new Mars(_worldCoords));

            var robot = new RobotTest.Robot( new Location(new Point(3, 2), Direction.North));
            var robotLocation = commandProcessorRobotWorld.ExecuteCommands("FRRFLLFFRRFLL", robot);

            var robot2 = new RobotTest.Robot( new Location(new Point(3, 2), Direction.North));
            var robotLocation2 = commandProcessorRobotWorld.ExecuteCommands("FRRFLLFFRRFLL", robot2);

            Assert.AreEqual("3 3 North LOST", robotLocation);
            Assert.IsFalse(robotLocation2.Contains("LOST"));
        }
コード例 #4
0
ファイル: RobotTests.cs プロジェクト: richinoz/Orchard1.6
        public void Perform_Full_Test_Using_Edge_Lines()
        {

            var commandProcessorFactory = new CommandProcessorFactory();
            var commandProcessorRobotWorld = commandProcessorFactory.Build<CommandProcessorRobotWorldLines>(new Mars(_worldCoords));

            var robot1 = new RobotTest.Robot(new Location(new Point(1, 1), Direction.East));
            var robot2 = new RobotTest.Robot(new Location(new Point(3, 2), Direction.North));
            var robot3 = new RobotTest.Robot(new Location(new Point(0, 3), Direction.West));

            var robotLocation1 = commandProcessorRobotWorld.ExecuteCommands("RFRFRFRF", robot1);
            var robotLocation2 = commandProcessorRobotWorld.ExecuteCommands("FRRFLLFFRRFLL", robot2);
            var robotLocation3 = commandProcessorRobotWorld.ExecuteCommands("LLFFFLFLFL", robot3);

            Assert.AreEqual("1 1 East", robotLocation1);
            Assert.AreEqual("3 3 North LOST", robotLocation2);
            Assert.AreEqual("2 3 South", robotLocation3);

        }