Beispiel #1
0
 public static IVehicleCommand GetVehicleCommand(Rotation rotation, ExplorationVehicle vehicle)
 {
     return(rotation switch
     {
         Rotation.L => new TurnVehicleLeft(vehicle),
         Rotation.R => new TurnVehicleRight(vehicle),
         Rotation.M => new MoveVehicle(vehicle),
         _ => throw new Exception(BusinessConstants.INVALID_ROTATION_VALUE),
     });
Beispiel #2
0
        public void MoveVehicle(Plateau plateau, ExplorationVehicle vehicle, IList <Rotation> rotations, IList <IPoint> busyPoints)
        {
            var vehiclePoint = new Point(vehicle.Point.PositionX, vehicle.Point.PositionY);
            var direction    = vehicle.GetDirection();

            var virtualVehicle   = ExplorationVehicles.Rover.Factory(vehiclePoint, direction, plateau);
            var destinationPoint = VehicleHelperFunctions.CheckBusyPointsRoute(virtualVehicle, rotations, busyPoints);

            VehicleHelperFunctions.CheckBorderLimits(plateau, destinationPoint);

            var vehicleCommandInvoker = new VehicleCommandInvoker();

            foreach (var rotation in rotations)
            {
                var vehicleCommand = VehicleCommandFactory.GetVehicleCommand(rotation, vehicle);
                vehicleCommandInvoker.Execute(vehicleCommand);
            }
        }
Beispiel #3
0
        public static IPoint CheckBusyPointsRoute(ExplorationVehicle virtualVehicle, IList <Rotation> rotations, IList <IPoint> busyPoints)
        {
            var vehicleCommandInvoker = new VehicleCommandInvoker();

            foreach (var rotation in rotations)
            {
                var vehicleCommand = VehicleCommandFactory.GetVehicleCommand(rotation, virtualVehicle);
                vehicleCommandInvoker.Execute(vehicleCommand);

                if (busyPoints
                    .Where(x => x.PositionX == virtualVehicle.Point.PositionX)
                    .Where(x => x.PositionY == virtualVehicle.Point.PositionY)
                    .Count() > 0)
                {
                    throw new HandledException(BusinessConstants.BUSY_POINT);
                }
            }
            return(virtualVehicle.Point);
        }
Beispiel #4
0
 internal TurnVehicleRight(ExplorationVehicle vehicle)
 {
     _vehicle = vehicle;
 }
Beispiel #5
0
 internal MoveVehicle(ExplorationVehicle vehicle)
 {
     _vehicle = vehicle;
 }
 internal TurnVehicleLeft(ExplorationVehicle vehicle)
 {
     _vehicle = vehicle;
 }
Beispiel #7
0
 public static void AddToVehicles(this IList <ExplorationVehicle> vehicles, ExplorationVehicle newVehicle, Plateau plateau)
 {
     vehicles.CheckVehiclesLimit(plateau);
     vehicles.Add(newVehicle);
 }