Ejemplo n.º 1
0
 public void Execute(CleaningRobot robot)
 {
     if (Validate(robot))
     {
         ExecuteCore(robot);
     }
 }
Ejemplo n.º 2
0
        public JsonResult Execute(JsonInput input)
        {
            var map          = ConvertMap(input.Map);
            var commandTypes = ConvertCommands(input.Commands);
            var facing       = ConvertToFacing(input.Start.Facing);
            var start        = new Point(input.Start.X, input.Start.Y);

            var robot = new CleaningRobot.Core.CleaningRobot(input.Battery, map, start, facing);

            robot.Run(commandTypes);

            var result = new JsonResult();

            result.Visited = robot.VisitedCells.OrderBy(p => p.X).ThenBy(p => p.Y);
            result.Cleaned = robot.CleanedCells.OrderBy(p => p.X).ThenBy(p => p.Y);
            result.Final   = new Position
            {
                X      = robot.Position.X,
                Y      = robot.Position.Y,
                Facing = ConvertToString(robot.Facing)
            };
            result.Battery = robot.Battery;

            return(result);
        }
Ejemplo n.º 3
0
        public override bool Validate(CleaningRobot robot)
        {
            var moveDirections        = GetMoveDirections(robot.Facing);
            var newPosition           = new Point(robot.Position.X + moveDirections.X, robot.Position.Y + moveDirections.Y);
            var cellTypeAtNewPosition = GetCellType(robot.Map, newPosition);

            return(cellTypeAtNewPosition == CellType.Space);
        }
Ejemplo n.º 4
0
        protected override void ExecuteCore(CleaningRobot robot)
        {
            var facing = robot.Facing + (_toRight ? 1 : -1);

            if (!Enum.IsDefined(typeof(Facing), facing))
            {
                facing = _toRight ? Facing.North : Facing.West;
            }
            robot.Facing = facing;
        }
Ejemplo n.º 5
0
 protected abstract void ExecuteCore(CleaningRobot robot);
Ejemplo n.º 6
0
 public virtual bool Validate(CleaningRobot robot)
 {
     return(true);
 }
Ejemplo n.º 7
0
        protected override void ExecuteCore(CleaningRobot robot)
        {
            var moveDirections = GetMoveDirections(robot.Facing);

            robot.Move(moveDirections.X, moveDirections.Y);
        }