RedShirtNo5
First Post
This was done in Visual Basic 6.0 using a single form with a button and a textbox. It took about 5-10 minutes to run.
The calculation of 31.12104 assumed point buy for stats below 8 scale linearly. I can calculate for other assumptions if folks are interested.
The calculation of 31.12104 assumed point buy for stats below 8 scale linearly. I can calculate for other assumptions if folks are interested.
Code:
Private Sub Command1_Click()
Dim V As Single
Dim P As Single
Dim A As Single
Dim Value As Single
Dim Probability As Single
Dim Strength As Integer
Dim Dexterity As Integer
Dim Intelligence As Integer
Dim Wisdom As Integer
Dim Charisma As Integer
Dim SampleText As String
V = 0
P = 0
' We will cycle through each possible stat array that could be created
For Strength = 3 To 18
For Dexterity = 3 To 18
For Constitution = 3 To 18
For Intelligence = 3 To 18
For Wisdom = 3 To 18
For Charisma = 3 To 18
' If the stat array is a "worthless character", then skip it
' Deal with no stats 14+ first
If Strength > 13 Or Dexterity > 13 Or Consitution > 13 _
Or Intelligence > 13 Or Wisdom > 13 Or Chrarisma > 13 Then
' Deal with total mods of 0 or below next
If Int((Strength - 10) / 2) + Int((Dexterity - 10) / 2)_
+ Int((Constitution - 10) / 2) + Int((Intelligence - 10) / 2)_
+ Int((Wisdom - 10) / 2) + Int((Charisma - 10) / 2) > 0 Then
' If the stat array is not a worthless character, calculate the
! point buy value (PBV) and the probability of that character occurring
Value = PBV(Strength) + PBV(Dexterity) + PBV(Constitution)_
+ PBV(Intelligence) + PBV(Wisdom) + PBV(Charisma)
Probability = prob(Strength) * prob(Dexterity) * prob(Constitution)_
* prob(Intelligence) * prob(Wisdom) * prob(Charisma)
' Add the weighted point buy value to a running total
V = V + Value * Probability
' Track the total probability (P) of getting a "non-worthless" character
' for normalization below
P = P + Probability
End If
End If
Next
Next
Next
Next
Next
Next
' We know the probability (1-P) of rolling a worthless character,
' and we calculated the average point buy value (V) that results
' from a single roll of 4d6dl. Since you keep rolling until you get a
' non-worthless character, the percentage chance (1-P) of a
' worthless ' character gets distributed across the possible
' non-worthless characters. Thus, we simply need to normalize
' the result.
A = V / P
' And display it
Text1.Text = "Final Result:" + Str(A)
End Sub
Function PBV(x)
' This assumes that point buy for stats below 8 scales linearly
If x < 15 Then PBV = x - 8
If x = 15 Then PBV = 8
If x = 16 Then PBV = 10
If x = 17 Then PBV = 13
If x = 18 Then PBV = 16
End Function
Function prob(x)
'These percentages taken from dcollins
' ([url="http://superdan.net.home.comcast.net/dndmisc/4d6curve.html"]http://superdan.net.home.comcast.net/dndmisc/4d6curve.html[/url])
If x = 3 Then prob = 0.0008
If x = 4 Then prob = 0.0031
If x = 5 Then prob = 0.0077
If x = 6 Then prob = 0.0162
If x = 7 Then prob = 0.0293
If x = 8 Then prob = 0.0478
If x = 9 Then prob = 0.0702
If x = 10 Then prob = 0.0941
If x = 11 Then prob = 0.1142
If x = 12 Then prob = 0.1289
If x = 13 Then prob = 0.1327
If x = 14 Then prob = 0.1235
If x = 15 Then prob = 0.1011
If x = 16 Then prob = 0.0725
If x = 17 Then prob = 0.0417
If x = 18 Then prob = 0.0162
End Function