Ejemplo n.º 1
0
        private void RunSimulation()
        {
            CordenatorTask = Task.Run(async() => {
                for (; ;)
                {
                    Cordinator();
                    RefreshViews();
                    await Task.Delay(TimeSpan.FromSeconds(5));
                }
            });

            RechargeStationTask = Task.Run(async() => {
                for (; ;)
                {
                    Drones.Where(d => d.State == DroneState.Recharging).ToList().ForEach((drone) => {
                        if (drone.Battery < 100)
                        {
                            drone.Battery += 1;
                        }
                        else
                        {
                            drone.State = DroneState.Waiting;
                        }
                    });
                    RefreshViews();
                    await Task.Delay(TimeSpan.FromMilliseconds(100));
                }
            });
        }
Ejemplo n.º 2
0
 private void Cordinator()
 {
     Positions.OrderByDescending(p => p.Position.ThreatLevel).ToList().ForEach((position) => {
         if (position.ActiveDrone != null && position.ActiveDrone.Battery <= 10)
         {
             var drone            = position.ActiveDrone;
             drone.State          = DroneState.Recharging;
             position.ActiveDrone = null;
         }
         else if (position.ActiveDrone == null && Drones.Where(d => d.State == DroneState.Waiting).Count() != 0)
         {
             var drone            = Drones.Where(d => d.State == DroneState.Waiting).FirstOrDefault();
             drone.State          = DroneState.OnGarde;
             position.ActiveDrone = drone;
         }
         else if (position.ActiveDrone == null && Drones.Where(d => d.State == DroneState.Waiting).Count() == 0)
         {
             var found = Positions.Where(p => p.ActiveDrone != null && p.Position.ThreatLevel < position.Position.ThreatLevel)
                         .OrderBy(p => p.Position.ThreatLevel).FirstOrDefault();
             if (found != null)
             {
                 var newDrone         = found.ActiveDrone;
                 found.ActiveDrone    = null;
                 position.ActiveDrone = newDrone;
             }
         }
         else if (position.ActiveDrone != null && position.ActiveDrone.Battery > 10)
         {
             position.ActiveDrone.Battery -= (int)Math.Round(position.Position.ThreatLevel * 0.1);
         }
     });
 }
Ejemplo n.º 3
0
 public List <Dron> GetDronesConCarga()
 {
     return(Drones.Where(dron => dron.Rutas.Count > 0).ToList());
 }