Ejemplo n.º 1
0
        private static Robot CreateRobotFromInputJsonData(string[] args)
        {
            var marsSurveillanceRobotInput = JsonManager.LoadInputJson(args[0]);
            var terrain         = JObject.Parse(marsSurveillanceRobotInput.ToString())["terrain"];
            var battery         = JObject.Parse(marsSurveillanceRobotInput.ToString())["battery"];
            var commands        = JObject.Parse(marsSurveillanceRobotInput.ToString())["commands"];
            var initialPosition = JObject.Parse(marsSurveillanceRobotInput.ToString())["initialPosition"];

            var robotStrategies = new[]
            { "E,R,F", "E,L,F", "E,L,L,F", "E,B,R,F", "E,B,B,L,F", "E,F,F", "E,F,L,F,L,F" };

            var facingControl = new FacingControl();
            var movingControl = new MovingControl();

            // Creamos um robot con los datos de entrada del fichero json,
            // y le añadimos un direccionamiento (facingControl) y un Navegador (navigationControl)

            var terrainElementTypes = TransformTerrainToTerrainElementTypes(terrain);
            var stackCommands       = TransformCommands(commands);

            var robot = lde_test.Robot.Create(
                initialPosition, battery, robotStrategies, facingControl, movingControl,
                terrainElementTypes, stackCommands);

            return(robot);
        }
Ejemplo n.º 2
0
 public RobotMemento(Position position, int battery, string[] strategies,
                     FacingControl facingControl, MovingControl movingControl)
 {
     Position          = position;
     Battery           = battery;
     NextStrategy      = 0;
     FacingControl     = facingControl;
     MovingControl     = movingControl;
     Strategies        = strategies;
     StackCommandTypes = new Stack <CommandType>();
     VisitedCells      = new List <Location>();
     VisitedCells.Add(Position.Location);
     SamplesCollected   = new List <ElementType>();
     SolutionStepByStep = new List <Result>();
 }
Ejemplo n.º 3
0
        // Factory Method

        public static Robot Create(JToken initialPosition, JToken battery, string[] robotStrategies,
                                   FacingControl facingControl, MovingControl movingControl,
                                   ElementType[,] terrainElementTypes, Stack <CommandType> stackCommandTypes)
        {
            // Validate parameters, throw exceptions

            var locationObject = JObject.Parse(initialPosition.ToString())["location"];
            int x = (int)JObject.Parse(locationObject.ToString())["x"];
            int y = (int)JObject.Parse(locationObject.ToString())["y"];

            var facingObject = (JToken)JObject.Parse(initialPosition.ToString())["facing"];
            var facing       = (Facing)Enum.Parse(typeof(Facing), facingObject.ToString());

            Location location = new Location(x, y);

            Position position = new Position(location, facing);

            return(new Robot(position, battery.Value <int>(), robotStrategies,
                             facingControl, movingControl,
                             terrainElementTypes, stackCommandTypes));
        }
Ejemplo n.º 4
0
        public Robot(Position position, int battery, string[] strategies,
                     FacingControl facingControl, MovingControl movingControl,
                     ElementType[,] terrainElementTypes, Stack <CommandType> stackCommandTypes)
        {
            Position          = position;
            Battery           = (battery > 0) ? battery : 0;
            NextStrategy      = 0;
            FacingControl     = facingControl;
            MovingControl     = movingControl;
            Strategies        = strategies;
            Terrain           = terrainElementTypes;
            StackCommandTypes = stackCommandTypes;
            VisitedCells      = new List <Location> {
                Position.Location
            };
            SamplesCollected = new List <ElementType>();

            SolutionStepByStep = new List <Result>();

            _robotMemento = new RobotMemento(position, battery, strategies, facingControl, movingControl);
        }