Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int testcount=150000; // number of simulated rounds
- bool playing[100]; for(int i=0; i<100; i++){playing[i]=1;} // whether a player is still active in a round
- int playingcount=100; // how many players are still active in a round
- int rollcount=0; // how many rolls there have been in a round
- int roundscore[100]; for(int i=0; i<100; i++){roundscore[i]=0;} // the round score for a player
- int roundhigh=0;
- long totalhigh=0;
- long totalscore[100]; for(int i=0; i<100; i++){totalscore[i]=0;} // the running total score for a player
- int wincount[100]; for(int i=0; i<100; i++){wincount[i]=0;} // the running total of rounds won for a player
- int ledcount[100]; for(int i=0; i<100; i++){ledcount[i]=0;} // the running total of rounds in the lead for a player
- for(int i=0; i<testcount; i++){
- while(playingcount>0){
- int roll=rand()%100+1;
- for(int b=0; b<100; b++){
- if(playing[b] && roll>b){roundscore[b]=roll-rollcount; totalscore[b]+=roundscore[b]; playing[b]=0; playingcount--; if(roundscore[b]>roundhigh){roundhigh=roundscore[b];} if(totalscore[b]>totalhigh){totalhigh=totalscore[b];}}
- }
- rollcount++;
- }
- for(int j=0; j<100; j++){if(roundscore[j]==roundhigh){wincount[j]++;}}
- for(int j=0; j<100; j++){if(totalscore[j]==totalhigh){ledcount[j]++;}}
- for(int j=0; j<100; j++){playing[j]=1;}
- playingcount=100;
- rollcount=0;
- for(int j=0; j<100; j++){roundscore[j]=0;}
- roundhigh=0;
- }
- cout << "\nAfter " << testcount << " simulated rounds:";
- for(int b=0; b<100; b++){cout << "\nPlayer " << b+1 << " has $" << totalscore[b] << ", won " << wincount[b] << " rounds, and led for " << ledcount[b] << " rounds.";}
- cin.get();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement