Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1.         void NethackLog::calc_gen_table(std::hash_set<std::string>& list, std::vector<TableLine>& gen_table)
  2.         {
  3.         Timer timer;
  4.             timer.start();
  5.  
  6.             std::hash_set<std::string>::iterator it;
  7.  
  8.             for(it = list.begin(); it != list.end(); ++it)
  9.                 calc_gen_table_line(*it, gen_table);
  10.            
  11.         timer.stop();
  12.             if(flag_timing)
  13.                 cout << "Time consumed by " __FUNCTION__ ": " << timer.getElapsedTimeInMilliSec() << " ms.\n";
  14.  
  15.         }
  16.             void NethackLog::calc_gen_table_line(std::string param, std::vector<TableLine>& gen_table)
  17.             {
  18.             TableLine rtl;
  19.  
  20.     rtl.gamesnum=0; rtl.scoremax=0; rtl.levelmax=0; rtl.asctries=0; rtl.ascgame=0; rtl.ascnum=0;
  21.     rtl.gamespc=0;  rtl.scoreavg=0; rtl.levelavg=0; rtl.ascpc=0;
  22.     int score_sum=0; int level_sum=0;
  23.  
  24.     for(unsigned int i = 0; i < log.size(); i++)
  25.     {
  26.             if(log[i].race == param)                            // If the race is equal to the parameter passed then..
  27.             {                                                  
  28.                 rtl.gen_name = param;                           // What race is this
  29.                 rtl.gamesnum++;                             // Increment the game counter
  30.                                                                
  31.                 if(log[i].score > rtl.scoremax)                
  32.                     rtl.scoremax = log[i].score;            // Assign value of score only if it's higher that what already exists
  33.                                                                
  34.                 score_sum += log[i].score;              // Sum each score
  35.                                                                
  36.                 if(log[i].maxdlvl > rtl.levelmax)              
  37.                     rtl.levelmax = log[i].maxdlvl;          // Assign value of max level reached only if it's higher that what already exist
  38.                    
  39.                 level_sum += log[i].maxdlvl;                // Sum each max dungeon level
  40.  
  41.                     if(log[i].asc == false && rtl.ascgame == 0)     // Increment when not ascended, but stop when the 1st ascension game has been reached
  42.                         rtl.asctries++;
  43.                             else if (rtl.ascgame == 0)          // On first ascension, set the game # that it was
  44.                                 rtl.ascgame = i+1;
  45.  
  46.                 if(log[i].asc == true)
  47.                     rtl.ascnum++;
  48.             }
  49.  
  50.     }
  51.     if(rtl.gamesnum != 0)
  52.     {  
  53.     rtl.gamespc = rtl.gamesnum / (float)log.size() * 100;               // Percentage of this race against total games
  54.     rtl.scoreavg = score_sum / (float)rtl.gamesnum;                 // Average score
  55.     rtl.levelavg = level_sum / (float)rtl.gamesnum;                 // Average max level reached
  56.     rtl.ascpc = rtl.ascnum / (float)rtl.gamesnum * 100;                 // Percentage of ascensions against the number of games of the race
  57.  
  58.     gen_table.push_back(rtl);
  59.     }
  60.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement