2009-08-24, 10:38 PM
(This post was last modified: 2009-08-24, 10:53 PM by singularity.)
Well, I wrote a new program to calculate this stuff. (Written in Excel VBA because almost everyone has Excel.) Inputs are taken from cells B1, B2, B3. (B1 = min damage, B2= max damage, B3 = Monster HP.)
To use this code, open Excel > open Visual Basic Editor (Alt+F11) > Insert > Module > Copy/Paste code into Module. Input values for min, max, monster hp in cells B1, B2, B3. Execute the code by Alt+F8 in main Excel window or by F5 in Visual Basic Editor. Output is spit out in column F.
For reference, this webpage has tables of probabilities when rolling 1 to 25 (6-sided) dice:
http://wizardofodds.com/gambling/dice2.html
If you set the min/max to match dice, the output of this program matches what you would expect from those tables. However, when you change the values to numbers similar to in-game damage numbers (i.e., min/max are over 10000), the calculation takes way too long. Or actually, it starts to have problems when min/max get over 500 or so.
So the way to go is to generate a sample and calculate probability using the sample. The result is not going to be completely accurate, but it should be very close as long as you have a large enough sample size.
To use this code, open Excel > open Visual Basic Editor (Alt+F11) > Insert > Module > Copy/Paste code into Module. Input values for min, max, monster hp in cells B1, B2, B3. Execute the code by Alt+F8 in main Excel window or by F5 in Visual Basic Editor. Output is spit out in column F.
Code:
Sub Test()
Dim min As Double
Dim max As Double
Dim monhp As Double
Dim n As Integer
Dim max_n As Integer
Dim damage As Double
Dim hko() As Double
Dim hkotemp() As Double
Dim sum As Double
Dim poss As Double
Dim prob As Double
min = ActiveSheet.Cells(1, 2)
max = ActiveSheet.Cells(2, 2)
monhp = ActiveSheet.Cells(3, 2)
max_n = Int(monhp / min)
If (max_n * min) < monhp Then
max_n = max_n + 1
End If
For a = 1 To (max_n + 1)
ActiveSheet.Cells(a, 6).Value = ""
Next a
ReDim hko(min To max)
For a = min To max
hko(a) = 1
Next a
sum = 0
poss = (max - min) + 1
For i = min To max
If i >= monhp Then
sum = sum + hko(i)
End If
Next i
prob = sum / poss * 100
ActiveSheet.Cells(1, 6).Value = prob
n = 1
Do While n < max_n
For x = 1 To n
Erase hkotemp()
ReDim hkotemp(((x * min) + min) To ((x * max) + max))
For y = min To max
For z = x * min To x * max
damage = y + z
If x = 1 Then
Erase hko()
ReDim hko(min To max)
For a = min To max
hko(a) = 1
Next a
hkotemp(damage) = hkotemp(damage) + hko(z)
Else
hkotemp(damage) = hkotemp(damage) + hko(z)
End If
Next z
Next y
Erase hko()
ReDim hko(((x * min) + min) To ((x * max) + max))
For g = ((x * min) + min) To ((x * max) + max)
hko(g) = hkotemp(g)
Next g
Next x
n = n + 1
sum = 0
For h = (n * min) To (n * max)
If h >= monhp Then
sum = sum + hko(h)
End If
Next h
poss = ((max - min) + 1) ^ n
prob = sum / poss * 100
ActiveSheet.Cells(n, 6).Value = prob
Loop
End Subhttp://wizardofodds.com/gambling/dice2.html
If you set the min/max to match dice, the output of this program matches what you would expect from those tables. However, when you change the values to numbers similar to in-game damage numbers (i.e., min/max are over 10000), the calculation takes way too long. Or actually, it starts to have problems when min/max get over 500 or so.
So the way to go is to generate a sample and calculate probability using the sample. The result is not going to be completely accurate, but it should be very close as long as you have a large enough sample size.

