Post by peddroelm on Oct 11, 2021 23:21:57 GMT -5
can run it even online like here www.tutorialspoint.com/execute_lua_online.php
edit any of these parameters - click execute
strong_dices_attack_pile = 36;
standard_dices_attack_pile = 12;
attacker_multiplier = 1.3;
strong_dices_defend_pile = 26;
standard_dices_defend_pile = 32;
defender_multiplier = 1.1;
local number_of_Checks= 15000;
BOOM ! sample output:
Checking [36s + 12] * 1.30 >= [26s + 32] * 1.10 ['Measured' 15000 times!] Probability ~ 74.92 %
Checking [26s + 12] * 0.70 >= [26s + 32] * 1.10 ['Measured' 15000 times!] Probability ~ 1.80 %
Checking [10s + 42] * 1.40 >= [46s + 22] * 0.90 ['Measured' 15000 times!] Probability ~ 32.02 %
lua source:
function RollnAccumulate_N_StrongDices(nr_strong_dices)
local strong_acc = 0;
for i = 1, nr_strong_dices, 1
do
if (math.random(10) > 6)
then
strong_acc = strong_acc + 1;
end
end
return strong_acc;
end
function RollnAccumulate_N_StandardDices(nr_standard_dices)
local standard_acc = 0;
for i = 1, nr_standard_dices, 1
do
if (math.random(10) > 8)
then
standard_acc = standard_acc + 1;
end
end
return standard_acc;
end
function check()
local A = math.floor(RollnAccumulate_N_StrongDices(strong_dices_attack_pile) * attacker_multiplier);
A = math.floor(A + RollnAccumulate_N_StandardDices(standard_dices_attack_pile) * attacker_multiplier);
local B = math.floor(RollnAccumulate_N_StrongDices(strong_dices_defend_pile) * defender_multiplier);
B = math.floor(B + RollnAccumulate_N_StandardDices(standard_dices_defend_pile)* defender_multiplier);
return (A >= B);
end
strong_dices_attack_pile = 36;
standard_dices_attack_pile = 12;
attacker_multiplier = 1.3;
strong_dices_defend_pile = 26;
standard_dices_defend_pile = 32;
defender_multiplier = 1.1;
local number_of_Checks= 15000;
math.randomseed(os.time())
math.random(); math.random(); math.random()
local checkpasses = 0;
for i = 1, number_of_Checks, 1
do
if ( check() )
then
checkpasses = checkpasses + 1;
end
end
local result_string ="";
result_string = string.format("%sChecking [%2ds + %2d] * %2.2f >= ", result_string, strong_dices_attack_pile, standard_dices_attack_pile, attacker_multiplier);
result_string = string.format("%s[%2ds + %2d] * %2.2f ", result_string, strong_dices_defend_pile, standard_dices_defend_pile, defender_multiplier );
result_string = string.format("%s ['Measured' %5d times!] Probability ~ %2.2f %% ", result_string, number_of_Checks ,100 * checkpasses/number_of_Checks );
print(result_string);
higher number of iterations , better approximation , less error BUT increases execution time which is an issue when 'on the fly' result capability is required (a mod that will show hit chances on the crew combat offensive talents targeting cursor maybe ..).. Since is just for player feedback - I'm sure a compromise between computation speed and acceptable error interval can be reached..