Code:
#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
int main(){
int deals_first_win = 0;
int deals_second_win = 0;
int tourney_first_win = 0;
int tourney_second_win = 0;
int iterations = 10000;
srand(time(0));
cout<<"start simulation\n";
for (int iteration=0; iteration<iterations; iteration++){
int stack_1 = 1;
int stack_2 = 2;
cout<<"Simulates tournament #"<<iteration<<"\r";
while ( (stack_1 > 0)&&(stack_2 > 0) ){
int winner = rand()%2;
if (winner == 0){
stack_1++;
stack_2--;
deals_first_win++;
} else {
stack_2++;
stack_1--;
deals_second_win++;
}
}
if (stack_1 == 0) tourney_second_win++;
if (stack_2 == 0) tourney_first_win++;
}
cout<<"tournament simulated: "<<iterations<<endl;
cout<<"Tournament win by first: "<<tourney_first_win<<endl;
cout<<"Tournament win by second: "<<tourney_second_win<<endl;
cout<<endl;
cout<<"Deals win by first: "<<deals_first_win<<endl;
cout<<"Deals win by second: "<<deals_second_win<<endl;
cout<<endl;
cout<<"tournaments wining first ratio: "<<(double)tourney_first_win/(double)iterations<<endl;
getchar();
return 0;
}
For stack sizes 1 and 2 chips:
For stack sizes 10 and 20 chips the same image
p.s. is there spoiler tag?Statistics: Posted by nefton — Mon Feb 03, 2014 5:01 pm
]]>