Пример #1
0
        private void LoadUnloadSkiers(SimulatedChairlift lift, long currentTime)
        {
            for (int i = 0; i < lift.ChairLift.PassengerCount && lift.SkiersWaiting.Count > 0; i++)
            {
                Skier skier = lift.SkiersWaiting.Dequeue();
                skier.StartTimeForCurrentStage = currentTime;
                skier.Location = lift.ChairLift.Top; // TODO: interpolate location between bottom and top
                Debug.Assert(!lift.SkiersRiding.Contains(skier));
                lift.SkiersRiding.Enqueue(skier);
            }

            for (int i = 0; i < lift.ChairLift.PassengerCount && lift.SkiersRiding.Count > 0; i++)
            {
                Skier skier = lift.SkiersRiding.Peek();
                if (currentTime - skier.StartTimeForCurrentStage >= lift.ChairLift.TimeToTop)
                {
                    skier = lift.SkiersRiding.Dequeue();
                    skier.StartTimeForCurrentStage = currentTime;
                    skier.Location = lift.ChairLift.Top;
                    // TODO: randomize new chairlift target
                    Debug.Assert(!lift.SkiersSkiingToThisLift.Contains(skier));
                    lift.SkiersSkiingToThisLift.Add(skier);
                }

                Debug.Assert(lift.SkiersRiding.Contains(skier) ^ lift.SkiersSkiingToThisLift.Contains(skier));
            }

            lift.LastLoadTime = currentTime;
        }
Пример #2
0
        private static void MoveSkiersToWaiting(long currentTime, SimulatedChairlift lift, Func <Skier, bool> doneWithRunPredicate)
        {
            List <Skier> remove = new List <Skier>();

            foreach (Skier skier in lift.SkiersSkiingToThisLift.Where(doneWithRunPredicate))
            {
                remove.Add(skier);
                skier.StartTimeForCurrentStage = currentTime;
                skier.Location = lift.ChairLift.Bottom;
                Debug.Assert(!lift.SkiersWaiting.Contains(skier));
                lift.SkiersWaiting.Enqueue(skier);
            }
            foreach (Skier skier in remove)
            {
                lift.SkiersSkiingToThisLift.Remove(skier);
            }
        }