Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void NethackLog::calc_gen_table(std::hash_set<std::string>& list, std::vector<TableLine>& gen_table)
- {
- Timer timer;
- timer.start();
- std::hash_set<std::string>::iterator it;
- for(it = list.begin(); it != list.end(); ++it)
- calc_gen_table_line(*it, gen_table);
- timer.stop();
- if(flag_timing)
- cout << "Time consumed by " __FUNCTION__ ": " << timer.getElapsedTimeInMilliSec() << " ms.\n";
- }
- void NethackLog::calc_gen_table_line(std::string param, std::vector<TableLine>& gen_table)
- {
- TableLine rtl;
- rtl.gamesnum=0; rtl.scoremax=0; rtl.levelmax=0; rtl.asctries=0; rtl.ascgame=0; rtl.ascnum=0;
- rtl.gamespc=0; rtl.scoreavg=0; rtl.levelavg=0; rtl.ascpc=0;
- int score_sum=0; int level_sum=0;
- for(unsigned int i = 0; i < log.size(); i++)
- {
- if(log[i].race == param) // If the race is equal to the parameter passed then..
- {
- rtl.gen_name = param; // What race is this
- rtl.gamesnum++; // Increment the game counter
- if(log[i].score > rtl.scoremax)
- rtl.scoremax = log[i].score; // Assign value of score only if it's higher that what already exists
- score_sum += log[i].score; // Sum each score
- if(log[i].maxdlvl > rtl.levelmax)
- rtl.levelmax = log[i].maxdlvl; // Assign value of max level reached only if it's higher that what already exist
- level_sum += log[i].maxdlvl; // Sum each max dungeon level
- if(log[i].asc == false && rtl.ascgame == 0) // Increment when not ascended, but stop when the 1st ascension game has been reached
- rtl.asctries++;
- else if (rtl.ascgame == 0) // On first ascension, set the game # that it was
- rtl.ascgame = i+1;
- if(log[i].asc == true)
- rtl.ascnum++;
- }
- }
- if(rtl.gamesnum != 0)
- {
- rtl.gamespc = rtl.gamesnum / (float)log.size() * 100; // Percentage of this race against total games
- rtl.scoreavg = score_sum / (float)rtl.gamesnum; // Average score
- rtl.levelavg = level_sum / (float)rtl.gamesnum; // Average max level reached
- rtl.ascpc = rtl.ascnum / (float)rtl.gamesnum * 100; // Percentage of ascensions against the number of games of the race
- gen_table.push_back(rtl);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement