Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,37 @@
|
|||
local fn RollTheDice( dice as long, sides as long ) as long
|
||||
long i, total = 0
|
||||
|
||||
for i = 1 to dice
|
||||
total += rnd(sides)
|
||||
next
|
||||
end fn = total
|
||||
|
||||
|
||||
void local fn CaclulateProbabilities( dice1 as long, sides1 as long, dice2 as long, sides2 as long )
|
||||
long i, player1, player2
|
||||
float total1 = 0, total2 = 0, total3 = 0
|
||||
|
||||
for i = 1 to 100000
|
||||
player1 = fn RollTheDice( dice1, sides1 )
|
||||
player2 = fn RollTheDice( dice2, sides2 )
|
||||
if ( player1 > player2 ) then total1++ : continue
|
||||
if ( player1 < player2 ) then total2++ : continue
|
||||
if ( player1 == player2 ) then total3++ : continue
|
||||
next
|
||||
|
||||
printf @"Dice cast %ld times.", i - 1
|
||||
printf @"Player 1 with %ld dice of %ld sides.", dice1, sides1
|
||||
printf @"Player 2 with %ld dice of %ld sides.", dice2, sides2
|
||||
printf @"Total wins Player 1 = %.f. Probability of winning: %0.4f%%.", total1, (total1 / i ) * 100
|
||||
printf @"Total wins Player 2 = %.f", total2
|
||||
printf @"Number of ties: %.f.", total3
|
||||
end fn
|
||||
|
||||
randomize
|
||||
print
|
||||
fn CaclulateProbabilities( 9, 4, 6, 6 )
|
||||
print
|
||||
fn CaclulateProbabilities( 5, 10, 6, 7 )
|
||||
print
|
||||
|
||||
HandleEvents
|
||||
Loading…
Add table
Add a link
Reference in a new issue