/// <summary>
        /// When this event is fired, the ore is unloaded, and attempting to charge begins as soon as
        /// unloading is complete
        /// </summary>
        /// <param name="world">The state of the world when the event is fired</param>
        public override void Run(State world)
        {
            station.oreMined           += robot.oreCapacity;
            robot.batteryPowerConsumed += (int)(robot.GetLoadFactor() * robot.distanceFromBase);
            robot.distanceFromBase      = 0;

            //Black box model: it takes time to unload, sometimes a bit more or a bit less
            AttemptChargingEnqueueEvent e = new AttemptChargingEnqueueEvent(robot, station, world.time + robot.GetUnloadTime());

            world.eventQueue.Enqueue(e, world.time + 1);
        }
Beispiel #2
0
 /// <summary>
 /// This event handles the chaining logic where robots may have to wait for a charging station.
 /// If a charger is available, claim it. If not, enqueue another attempt event after the next
 /// charging complete event.
 /// </summary>
 /// <param name="world">The state of the world right now.</param>
 public override void Run(State world)
 {
     if (station.chargingStationsInUse == station.maxChargingStations)
     {
         var nextChargingExitEvent = world.eventQueue.First(exitTime => exitTime.GetType().Equals(typeof(ChargingCompleteEvent)));
         var nextAttemptTime       = world.eventQueue.GetPriority(nextChargingExitEvent);
         var e = new AttemptChargingEnqueueEvent(robot, station, nextAttemptTime + 1);
         world.eventQueue.Enqueue(e, e.GetTime());
     }
     else
     {
         station.chargingStationsInUse += 1;
         robot.state = RobotState.charging;
         WorldEvent e = new ChargingCompleteEvent(robot, world.time + robot.getChargingTime());
         world.eventQueue.Enqueue(e, e.GetTime());
     }
 }