dicegame :=
proc(numexpt)
# probabilistic model to find the probability of the attack dice winning
#
# input parameters:
# numexpt = number of experiments simulated
# output:
# prob = the probability the attacker wins
#
local r,attackprob, attackdice1, attackdice2, defensedice1,numexpt, ctexpt;
r := rand(1..6);
wins := 0;
for ctexpt from 1 to numexpt
do
attackdice1 := rand();
attackdice2 := rand();
defensedice1 = rand();
max := max(attackdice1,attackdice2);
if max > defensedice1
then wins := wins +1
end if;a
od;
attackprob:= evalf(wins / numexpt);
lprint(`average number of exposures =`,wins);
defenseprob :=100-attackprob;
lprint(`the probability of the defense winning =`,defenseprob);
end;