#!/usr/bin/ruby
def random2(x)
rand(0...x)
end
def roll_dice(n,d)
r = 0
for i in 1..n
r += 1 + random2(d)
end
return r
end
def div_rand_round(n, d)
rem = n%d
q = n/d
if rem != 0 && random2(d) < rem
q += 1
end
return q
end
def skill_rdiv(invo, n, d)
div_rand_round(invo*n*256, d*256)
end
def do_ability(mon_type, same_species, invo)
pow = 10 + skill_rdiv(invo, 1, 3)
cast_healing(mon_type, same_species, pow, invo)
end
def cast_healing(mon_type, same_species, pow, invo)
healed = pow + roll_dice(2, pow) - 2
can_pacify_monster(mon_type, same_species, healed, invo)
end
def can_pacify_monster(mon_type, same_species, healed, invo)
factor = 1
divisor = 3
case mon_type
when :animal
factor = 3
when :undead
divisor = 4
when :demon
divisor = 5
when :holy
divisor = 2
end
factor = 2 if same_species
factor * random2( ((invo*healed)+healed)/divisor )
end
def prob(n, mon, same_species, invo)
hist = []
n.times do
h = do_ability(mon, same_species, invo)
hist[h] = 0 unless hist[h]
hist[h] += 1
end
for i in 0...hist.size
hist[i] = 0 unless hist[i]
end
p = []
for i in 0...hist.size
p[i] = 0
for j in 0...i
p[i] += hist[j]
end
p[i] = 1 - (1.0*p[i]) / n
end
return p
end
def main
n = 100000
p1 = prob(n, :animal, false, 27)
p2 = prob(n, :demon, false, 27)
p3 = prob(n, :undead, false, 27)
p4 = prob(n, :other, false, 27)
size = [p1.size, p2.size, p3.size, p4.size].max
for i in 0...size
data = [i, p1[i], p2[i], p3[i], p4[i]]
for j in 0...data.size
data[j] = 0 unless data[j]
end
print "%d %.5f %.5f %.5f %.5f \n" % data
end
end
main