Ejemplo n.º 1
0
        private static void SimulateRace(int tournamentID, int raceNum)
        {
            // generate simulation
            Dictionary <int, int> simLaneTimes = new Dictionary <int, int>();

            ITournament tournament = TournamentManager.GetTournament(tournamentID);

            for (int i = 0; i < tournament.NumLanes; i++)
            {
                simLaneTimes.Add(i + 1, _random.Next(350000, 500000));
            }

            // identify the sleep times
            List <KeyValuePair <int, int> > orderedLaneTimes = simLaneTimes.OrderBy(p => p.Value).ToList();
            List <int> sleepTimes  = new List <int>();
            int        elapsedTime = 0;

            for (int i = 0; i < orderedLaneTimes.Count; i++)
            {
                sleepTimes.Add(orderedLaneTimes[i].Value - elapsedTime);
                elapsedTime = orderedLaneTimes[i].Value;
            }

            // simulate a delay in pressing the start button
            Thread.Sleep(_random.Next(500, 3000));

            for (int i = 0; i < orderedLaneTimes.Count; i++)
            {
                // sleep until the car crosses the finish line
                Thread.Sleep(sleepTimes[i] / 100);

                // simulate DNF
                int dnf = _random.Next(1, 20);
                if (dnf != 7) // 7 is random - just one number out of 20 which should be hit about 5% of the time
                {
                    // only update the race time if this is NOT a DNF

                    // update the race
                    LaneResultAdded?.Invoke(new LaneResultEventArgs(tournamentID, raceNum, orderedLaneTimes[i].Key, orderedLaneTimes[i].Value));
                }
            }

            while (!_stopMonitoring)
            {
                Thread.Sleep(500);
            }
        }
Ejemplo n.º 2
0
        public static RlmGetRacesResponse GenerateRaces(int tournamentID)
        {
            IRlmRepository      repo   = RepositoryManager.GetDefaultRepository();
            RlmGetRacesResponse result = null;

            lock (_lock)
            {
                Tournament tournament = repo.LoadTournament(tournamentID);

                // generate the races
                TournamentManager.GenerateRaces(ref tournament);

                repo.SaveTournament(tournament);
                result = GetRaces(tournament);
            }

            RacesUpdated?.Invoke(tournamentID, new RacesUpdatedEventArgs(result));
            CurrentRaceChanged?.Invoke(tournamentID, new CurrentRaceChangedEventArgs(null, GetCurrentRace(tournamentID)));
            //RaceUpdated?.Invoke(tournamentID, new RaceUpdatedEventArgs(GetCurrentRace(tournamentID)));
            NextRacesUpdated?.Invoke(tournamentID, new NextRacesUpdatedEventArgs(GetNextRaces(tournamentID)));
            StandingsUpdated?.Invoke(tournamentID, new StandingsUpdatedEventArgs(GetStandings(tournamentID)));

            return(result);
        }