|
|
|
|
|
|
|
|
This program simulates a game of raquetball between two
players called 'A' and 'B'. The ability of each player is
indicated by a probability (a number between 0 and 1) that
the player wins the point when serving.Player A always
has the first serve
What is the prob. player A wins the serve? .5
What is the prob player B wins the serve? .7
How many games to simulate? 1200
0.13
0.19
0.74
0.49
0.2
0.36
0.9
0.43
0.24
0.34
0.02
0.45
0.28
0.45
0.79
0.94
0.94
0.87
0.36
0.81
0.46
0.17
0.58
0.48
0.88
0.3
0.21
0.63
0.66
0.92
0.26
0.01
0.74
0.07
0.7
0.53
0.09
0
0.37
0.37
0.37
0.51
Games simulated: 42
Wins for A: 36 0.857143
Wins for B: 6 0.142857
Program ended with exit code: 0 |
| In C++ is not the same, it is a big difference. I thought that this program can't be translated in C++ to return the same result because if I use the same functions as in the python program and pointers to return multiple values, the result is the same as in this program that I will post here. |
|
|
scoreA = 0, scoreB = 0, winsA = 0, winsB = 0 A serves, A scores scoreA = 1, scoreB = 0, winsA = 1, winsB = 0 A serves, A scores scoreA = 2, scoreB = 0, winsA = 2, winsB = 0 A serves, B scores scoreA = 2, scoreB = 0, winsA = 3, winsB = 0 B serves, B scores scoreA = 2, scoreB = 1, winsA = 4, winsB = 0 B serves, B scores scoreA = 2, scoreB = 2, winsA = 4, winsB = 1 |
while (((scoreA != 15) or (scoreB != 15)) and (game_no != n)) |
|