Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do you calculate %xHKO?
#22
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.


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 Sub
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.
Reply


Messages In This Thread
How do you calculate %xHKO? - by Dusk - 2009-08-14, 11:40 AM
How do you calculate %xHKO? - by Kortestanov - 2009-08-14, 12:45 PM
How do you calculate %xHKO? - by Shidoshi - 2009-08-14, 01:59 PM
How do you calculate %xHKO? - by Stereo - 2009-08-14, 02:00 PM
How do you calculate %xHKO? - by KaidaTan - 2009-08-14, 05:29 PM
How do you calculate %xHKO? - by Russt - 2009-08-14, 05:41 PM
How do you calculate %xHKO? - by modular - 2009-08-14, 06:59 PM
How do you calculate %xHKO? - by Russt - 2009-08-14, 07:01 PM
How do you calculate %xHKO? - by Shidoshi - 2009-08-14, 08:45 PM
How do you calculate %xHKO? - by singularity - 2009-08-15, 06:23 AM
How do you calculate %xHKO? - by Russt - 2009-08-15, 12:56 PM
How do you calculate %xHKO? - by Shady - 2009-08-15, 04:30 PM
How do you calculate %xHKO? - by singularity - 2009-08-18, 12:19 AM
How do you calculate %xHKO? - by Stereo - 2009-08-18, 12:29 AM
How do you calculate %xHKO? - by Russt - 2009-08-18, 12:39 AM
How do you calculate %xHKO? - by Dusk - 2009-08-18, 12:57 AM
How do you calculate %xHKO? - by modular - 2009-08-18, 12:57 AM
How do you calculate %xHKO? - by Russt - 2009-08-18, 01:03 AM
How do you calculate %xHKO? - by Dusk - 2009-08-18, 01:21 AM
How do you calculate %xHKO? - by Dusk - 2009-08-23, 01:45 PM
How do you calculate %xHKO? - by Russt - 2009-08-23, 01:56 PM
How do you calculate %xHKO? - by singularity - 2009-08-24, 10:38 PM
How do you calculate %xHKO? - by Russt - 2009-08-24, 10:51 PM
How do you calculate %xHKO? - by Noah - 2009-08-26, 04:38 PM
How do you calculate %xHKO? - by rainbowBean - 2009-12-14, 08:22 AM
How do you calculate %xHKO? - by KaidaTan - 2009-12-14, 09:07 AM
How do you calculate %xHKO? - by Stereo - 2009-12-14, 12:19 PM
How do you calculate %xHKO? - by KaidaTan - 2009-12-14, 04:19 PM
How do you calculate %xHKO? - by shouri - 2009-12-14, 04:42 PM
How do you calculate %xHKO? - by KaidaTan - 2009-12-14, 05:02 PM
How do you calculate %xHKO? - by Russt - 2009-12-14, 08:46 PM
How do you calculate %xHKO? - by shouri - 2009-12-14, 08:56 PM
How do you calculate %xHKO? - by Noah - 2009-12-14, 09:32 PM
How do you calculate %xHKO? - by Stereo - 2009-12-14, 09:33 PM
How do you calculate %xHKO? - by Russt - 2009-12-14, 09:40 PM
How do you calculate %xHKO? - by KaidaTan - 2009-12-14, 10:32 PM
How do you calculate %xHKO? - by rainbowBean - 2009-12-14, 11:01 PM
How do you calculate %xHKO? - by Russt - 2009-12-15, 03:50 AM
How do you calculate %xHKO? - by KaidaTan - 2009-12-15, 03:54 AM
How do you calculate %xHKO? - by Stereo - 2009-12-15, 03:51 PM
How do you calculate %xHKO? - by Noah - 2009-12-16, 09:28 PM
How do you calculate %xHKO? - by Stereo - 2010-01-18, 09:17 PM
How do you calculate %xHKO? - by Jellyflower - 2010-02-23, 08:30 PM
How do you calculate %xHKO? - by Jellyflower - 2010-02-23, 10:18 PM
How do you calculate %xHKO? - by KaidaTan - 2010-02-23, 10:34 PM
How do you calculate %xHKO? - by Russt - 2010-02-23, 10:42 PM
How do you calculate %xHKO? - by Noah - 2010-03-06, 06:51 AM
How do you calculate %xHKO? - by Russt - 2010-03-06, 09:08 AM
How do you calculate %xHKO? - by Shidoshi - 2010-03-06, 10:40 AM
How do you calculate %xHKO? - by Russt - 2010-03-06, 10:50 AM
How do you calculate %xHKO? - by Stereo - 2010-03-06, 11:42 AM
How do you calculate %xHKO? - by Noah - 2010-03-06, 12:39 PM
How do you calculate %xHKO? - by Russt - 2010-03-06, 02:57 PM
How do you calculate %xHKO? - by Noah - 2010-03-08, 12:00 PM
How do you calculate %xHKO? - by Kortestanov - 2010-05-03, 08:39 AM
How do you calculate %xHKO? - by Nikkey - 2010-05-03, 12:11 PM
How do you calculate %xHKO? - by Kortestanov - 2010-05-03, 02:16 PM
How do you calculate %xHKO? - by KaidaTan - 2010-05-03, 02:24 PM
How do you calculate %xHKO? - by shouri - 2010-05-03, 02:24 PM
How do you calculate %xHKO? - by Nikkey - 2010-05-03, 02:56 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)