View Single Post
  #3  
Old 11-24-2024, 04:37 PM
Jimjam Jimjam is offline
Planar Protector


Join Date: Jul 2013
Posts: 12,758
Default

Really interesting code there. Thanks for posting it. What is the source? If I understand correctly it creates a loaded d20 dice where the weighting of the faces is derived from a complex comparison of offense and mitigation.

It seems mitigation gets scaled to the attacker's offense by subtracting the average between the attacker's offence and the defender's mitigation from the mob's mitigation, producing the adjusted scaled mitigation. I supose this is to make it so that while it is possible to squelch a weaker' mob's mitigation to some degree, they always have at least some chance to mitigate?

The code then does some comparisons of the adjusted mitigation value to offence to create a multiplier based on offense.

The next bit I'm not sure of, but the presence of a mean and standard deviation along with other values suggests a normal distribution is created, the mean for which is set based on the offence mitigation comparisons.

This explains why we have spikes counts of the lower and highest hit values. As a normal distribution has been generated, theoretically there are no limits to the highest and lowest values of d generated, so the values which are out of bounds are getting lumped into the dice as rolls of 1 or 20 (i.e. min or max damage).

Can stats/code fans verify I'm understanding this snippet of code correctly? Are there any details where you can provide deeper understanding either? My interpretation seems to match my previously reported understanding, but I admit my interpretation was likely coloured by my existing beliefs.

Edit: Here is the code DSM kindly shared, which I interpret as creating a loaded d20 damage roll with the faces weighted by a complex comparison of offence and mitigation transformed into a normal distribution.
 

function RollD20(offense, mitigation)
local diff, mult1, mult2;

mitigation = mitigation - (mitigation - offense) / 2;
diff = offense - mitigation;
if ( offense > 30 ) then
mult1 = offense / 200 + 25.75;
if ( mitigation / offense < 0.35 ) then
mult1 = mult1 + 1;
elseif ( mitigation / offense > 0.65 ) then
mult1 = mult1 - 1;
end
else
mult1 = 11.5 + offense / 2;
end
if ( offense > 30 ) then
mult2 = offense / 140 + 18.5;
else
mult2 = 14 + offense / 6;
end

local mean = 0;

if ( offense > mitigation ) then
mean = diff / offense * mult1;
elseif ( mitigation > offense ) then
mean = diff / mitigation * mult2;
end

local stddev = 8.8;
local theta = 2 * math.pi * math.random();
local rho = math.sqrt(-2 * math.log(1 - math.random()));
local d = mean + stddev * rho * math.cos(theta);

if ( d < -9.5 ) then
d = -9.5;
elseif ( d > 9.5 ) then
d = 9.5;
end
d = d + 11;
d = math.floor(d);
return d;
end
Last edited by Jimjam; 11-24-2024 at 04:51 PM..
Reply With Quote