matteoferla / DnD-battler

A 5e D&D encounter simulator written for my own amusement to test some hypotheses.
MIT License
80 stars 31 forks source link

Fixed a bug in average roll calculation #9

Closed aaronhendry closed 5 years ago

aaronhendry commented 5 years ago

The way you're calculating the average dice roll doesn't match the WotC way. The issue is twofold, actually.

1) For single dice rolls, you're taking the ceiling of the average rather than the floor (well, technically you're rounding it, but this will always result in an x.5 value, so it's effectively a ceiling). This means that for instance for a 1d4 you calculate the average damage as round(4/2+1) = 3. If you compare this with a Camel (MM pg 320), the stated average for a 1d4 attack is 2. This leads to monsters/NPCs doing slightly more damage on average than they should.

2) For multiple dice rolls, you're rounding too soon, which also results in monsters doing more damage than they should. For example, consider the Tarrasque's bite attack (4d12+10). The stated average for this in the MM is 36, but using your approach you get 38. This is because you're basically doing round(12/6+1)4, rather than floor((12/6+1)4).

matteoferla commented 5 years ago

Thanks for fixing it!
(And sorry the code is such a mess, it was never meant to be anywhere this large)