void Lottery::run() { srand(time(NULL)); generateTeams(); generateLotteryNumbers(); assignTeams(); generateOutputFile(); }
void AgentDatabase::generateAgents(PlayerList* players) { PlayerList::Player player; //We do NOT want more than 85 players! Even 85 is pushing it. for(int i0 = 0; i0 < 85; i0++) { player = players->getPlayer(); if(player.firstName == "" && player.lastName == "") { //We're done with the loop. break; } //Otherwise, if we have some data, define a new player. Agent agent(player.lastName, player.firstName, defaultEncryptSeconds, defaultTapSeconds); agents.push_back(agent); activeAgents++; } /*Select the infiltrator. (Variable named for 1600s double agent Samuel Morland in the War of the Three Kingdoms)*/ int morland = (keygen->rollDice(1, agents.size())) - 1; agents[morland].infiltrator = true; /*Assign agent IDs (1-size) using keygen's sequence.*/ keygen->sequenceReset(agents.size()); for(unsigned int i1 = 0; i1 < agents.size(); i1++) { int num = keygen->sequenceNext(); agents[i1].id = num; //While we're in that loop, assign the security code. agents[i1].securitycode = keygen->getRandom(); } //Assign the field codes. for(unsigned int i2 = 0; i2 < agents.size(); i2++) { //Use the sequencer to randomly fetch unique numbers between 1-99. keygen->sequenceReset(99); //Assign the field codes. Always give five extras. for(unsigned int c = 0; c < (5+agents.size()); c++) { /*Create the code using the agent id and a random number from the sequencer.*/ int code = keygen->generateKey(agents[i2].id, keygen->sequenceNext()); agents[i2].codes.insert(code); codesmaster.insert(code); } } /*Resort vector using std::sort (<algorithm>) and the overloaded < operator defined in Agent. http://stackoverflow.com/a/1380496/472647*/ std::sort(agents.begin(), agents.end(), std::less<Agent>()); /*Determine how many people to a team. If we have a lot of people, the minimum should be one quarter the number of players. If we have 8 or less, the minimum should always be 2. For the max, we never want more than 4 people to a team, but if we have less than 8 players, the max MUST be half the number of players.*/ int teamSize = keygen->rollDice( (agents.size() > 8 ? agents.size() / 4 : 2), (agents.size() > 8 ? 4 : agents.size()/2)); /*The number of teams is the number of players divided by the size of the teams. Any extra will be distributed in.*/ int teamNum = agents.size() / teamSize; //However, we never want more than 16 teams or less than 2. teamNum > 16 ? teamNum = 16 : teamNum; teamNum < 2 ? teamNum = 2 : teamNum; //Generate the teams. generateTeams(teamNum); /*Loop through the teams, assigning <teamSize> players using keygen->sequenceNext().*/ keygen->sequenceReset(agents.size()); for(unsigned int t=0;t<teams.size();t++) { for(int ts=0; ts<teamSize; ts++) { int ta = keygen->sequenceNext(); agents[ta-1].team = &teams[t]; } } /*Then, if keygen->sequenceEmpty() is false, loop through again, assigning one player via keygen->sequenceNext() to each until keygen->sequenceEmpty() returns true.*/ while(!keygen->sequenceEmpty()) { for(unsigned int t1=0;t1<teams.size();t1++) { int ta = keygen->sequenceNext(); agents[ta-1].team = &teams[t1]; if(keygen->sequenceEmpty()) { break; } } } }