I'm doing all of this without checking my work, so if I err don't be surprised -- just give me the line I screwed up on.
CRGreathouse said:
A = 1dY+Z
If Z >= 0: A = (Y + 1) / 2 + Z
If -Y < Z < 0: A = (Y + Z)(Y + Z - 1)/(2Y) + 1
If Z <= -Y: A = 1
So if Z >= -Y:
A = (Y + min(0, Z))(Z + max(0, Z) + Y - 1) / (2Y) + 1
In general, then, A = max(0, (Y + min(0, Z)))(Z + max(0, Z) + Y - 1) / (2Y) + 1
Against DR D/-- (or any unbeatable DR):
A = max(0, max(0, (Y + min(0, Z)))(Z + max(0, Z) + Y - 1) / (2Y) + 1 - D)
With hit chance H (5% to 95%):
A = H max(0, max(0, (Y + min(0, Z)))(Z + max(0, Z) + Y - 1) / (2Y) + 1 - D)
Now it starts to get hard. Critical hits change stratagy when dealing with DR. Adding in threat chance T and critical multiplier M:
A = H(1 - T) max(0, max(0, (Y + min(0, Z)))(Z + max(0, Z) + Y - 1) / (2Y) + 1 - D) + HT max(0, M max(0, (Y + min(0, Z)))(Z + max(0, Z) + Y - 1) / (2Y) + 1 - D)
Actually, the above line isn't strictly correct -- it would give average damage 0 for 1d4/x4 vs. DR 10, when actually the average damage is roughly 1/700 (depending on hit chance). Suggestions here? I guess I need a multidie version of my second equation (quoted above).
In any case, this is just demonstrating how difficult it is to come up with a good formula to maximize. The iterative attacks are by far the hardest part, becasue they really do cause overflow-type errors -- most of the work for the above formula is just covering for corner cases like the oddball above.
Adding PA into these formulae wouldn't be hard, but finding breakpoints would be silly because of the number of cases needed with all the floor functions.