11
Programming / Shooting accuracy (again)
« Last post by jnarical on Today at 01:37:22 am »Ok. I finally found an elephant in the room. There's this block of code:
First condition is met 75% of times (I've run a simulation with 201x201 tiles with target in the center), that's the share of cases where xyShift (which affects spread and hit chance) is calculated from 1/4 of xDist and full yDist.
Second condition happens in remaining 25% - when target is located along X axis inside 60% shooting angle. In this case, spread is significally lower and hit chance is significally higher.
The ultimate goal here is to make spread uniform, preserving vanilla chances to hit.
Here's the solution I suggest:
First of all, (xDist + yDist) / 2 used in 25% cases in vanilla - gives way too small dispersion and increases chance to hit a lot.
So I suggest to use longer Dist value as a base and add a fraction of smaller value. That way, we increase 75% number of cases of "bad dispersion" to 100%, but it's uniform.
Then, I updated my script for 201x201 "map" simulation, calculating the average xyShift for all tiles. That gave me a value of 1038.50
Next, I tested my suggested variant - and got 1206.0
That corresponds with new increased xyShift.
And then I got a multiplier: 1038.5 / 1206 = 0,861111111
With it, I got AVERAGE xyShift = 1038.5 for new algorithm, just the same as vanilla. For 201x201 map, it's 40400 simulations from all possible directions and distances.
In conclusion - new algorithm gives the same overall chances to hit. Compared to vanilla, it gives better vertical shots, but worse horizontal ones.
Code: [Select]
int xDist = abs(origin.x - target->x);
int yDist = abs(origin.y - target->y);
int zDist = abs(origin.z - target->z);
int xyShift, zShift;
if (xDist / 2 <= yDist) //yes, we need to add some x/y non-uniformity
xyShift = xDist / 4 + yDist; //and don't ask why, please. it's The Commandment
else
xyShift = (xDist + yDist) / 2; //that's uniform part of spreading
First condition is met 75% of times (I've run a simulation with 201x201 tiles with target in the center), that's the share of cases where xyShift (which affects spread and hit chance) is calculated from 1/4 of xDist and full yDist.
Second condition happens in remaining 25% - when target is located along X axis inside 60% shooting angle. In this case, spread is significally lower and hit chance is significally higher.
The ultimate goal here is to make spread uniform, preserving vanilla chances to hit.
Here's the solution I suggest:
Code: [Select]
if xDist <= yDist:
xyShift = xDist / 4 + yDist
else:
xyShift = yDist / 4 + xDist
xyShift *= 0.86111
First of all, (xDist + yDist) / 2 used in 25% cases in vanilla - gives way too small dispersion and increases chance to hit a lot.
So I suggest to use longer Dist value as a base and add a fraction of smaller value. That way, we increase 75% number of cases of "bad dispersion" to 100%, but it's uniform.
Then, I updated my script for 201x201 "map" simulation, calculating the average xyShift for all tiles. That gave me a value of 1038.50
Next, I tested my suggested variant - and got 1206.0
That corresponds with new increased xyShift.
And then I got a multiplier: 1038.5 / 1206 = 0,861111111
With it, I got AVERAGE xyShift = 1038.5 for new algorithm, just the same as vanilla. For 201x201 map, it's 40400 simulations from all possible directions and distances.
In conclusion - new algorithm gives the same overall chances to hit. Compared to vanilla, it gives better vertical shots, but worse horizontal ones.