Exemple #1
0
        public Session(Random coin, PlayerPool players, LocationPool locations)
        {
            rand      = coin;
            sessionId = Guid.NewGuid();

            int playerIdx = rand.Next(0, players.numPlayers - 1);

            playerId = players.players[playerIdx];

            //20% master, 30% medium, 50% casual
            level = levelList.beginner;
            double nextRandDbl = rand.NextDouble();

            if (nextRandDbl >= 0.8)
            {
                level = levelList.medium;
            }
            else if (nextRandDbl >= 0.5)
            {
                level = levelList.casual;
            }

            cities        = locations;
            numCities     = cities.numCities;
            citiesInChunk = numCities / 60; //rotate the world in 60 minutes
        }
Exemple #2
0
        static void GenerateData(GenConfig config)
        {
            Queue <LogRecord> futureLogQ  = new Queue <LogRecord>();
            DateTimeOffset    currentTime = DateTimeOffset.UtcNow;
            DateTimeOffset    endTime     = currentTime.AddHours(config.nDurationHours);
            int          totalSession     = 0;
            Random       coin             = new Random();
            PlayerPool   players          = new PlayerPool(config.numPlayers);
            LocationPool locations        = new LocationPool(config.cityFile);

            while (endTime.Subtract(currentTime) >= TimeSpan.Zero)
            {
                Session curSession = new Session(coin, players, locations);

                //start
                curSession.setEvent(Session.eventTypeList.gameStart, currentTime);
                LogRecord rec = new LogRecord(curSession);
                outputLog(rec, config);

                //reachLevel
                int seconds2Level = coin.Next(5, 20);
                curSession.setEvent(Session.eventTypeList.levelReached, currentTime.AddSeconds(seconds2Level));
                rec = new LogRecord(curSession);
                futureLogQ.Enqueue(rec);

                //purchase
                int seconds2Purchase = coin.Next(2, 10);
                curSession.setEvent(Session.eventTypeList.itemPurchased, currentTime.AddSeconds(seconds2Purchase));
                rec = new LogRecord(curSession);
                futureLogQ.Enqueue(rec);

                //end
                int seconds2End = Math.Max(seconds2Level, seconds2Purchase) + coin.Next(3, 7);
                curSession.setEvent(Session.eventTypeList.gameEnd, currentTime.AddSeconds(seconds2End));
                rec = new LogRecord(curSession);
                futureLogQ.Enqueue(rec);

                //output those session end records that happened in the past not future
                while (futureLogQ.Count > 0)
                {
                    LogRecord drec, prec;
                    prec = (LogRecord)futureLogQ.Peek();
                    DateTimeOffset oldest = DateTimeOffset.Parse(prec.eventTime, null, System.Globalization.DateTimeStyles.AssumeUniversal);
                    if (currentTime.Subtract(oldest) >= TimeSpan.Zero)
                    {
                        drec = (LogRecord)futureLogQ.Dequeue();
                        outputLog(drec, config);
                    }
                    else
                    {
                        break;
                    }
                }

                System.Threading.Thread.Sleep(config.msPerSession);
                Console.WriteLine("Total:" + totalSession++ + ", In queue:" + futureLogQ.Count);
                currentTime = DateTimeOffset.UtcNow;
            } // while - within duration
        }