示例#1
0
        public void UpdateQueue(int curentTime)
        {
            var carsToAdd  = from c in CarsToSpawn where c.EntryTime == curentTime select c;
            var carsToAdd2 = carsToAdd.ToList();

            if (carsToAdd2.Count > 0)
            {
                foreach (var a in carsToAdd2)
                {
                    QueuedCars.Add(a);
                    CarsToSpawn.Remove(a);
                }
            }
        }
示例#2
0
        private void PopulateCarsToSpawn()
        {
            var from      = EntryPosition;
            var totalCars = (int)(((double)Pattern.CarsPerMin / 60) * Roundabout.SimulationDuration);

            for (var i = 0; i < totalCars; i++)
            {
                EntryPosition to;
                var           dirInt = Tools.RandomGen.Next(0, 100);
                if (dirInt <= Pattern.ToNorthPerc)
                {
                    to = EntryPosition.North;
                }
                else if (dirInt <= Pattern.ToWestPerc)
                {
                    to = EntryPosition.West;
                }
                else if (dirInt <= Pattern.ToSouthPerc)
                {
                    to = EntryPosition.South;
                }
                else
                {
                    to = EntryPosition.East;
                }


                var time           = (int)(Roundabout.SimulationDuration * Tools.RandomGen.NextDouble());
                var timeCollisions = from a in CarsToSpawn where a.EntryTime == time select a;
                while (timeCollisions.Any())
                {
                    time           = (int)(Roundabout.SimulationDuration * Tools.RandomGen.NextDouble());
                    timeCollisions = from a in CarsToSpawn where a.EntryTime == time select a;
                }

                CarsToSpawn.Add(new Car(time, from, to));
            }
        }