Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # density for the _number_ of rolled exploding dices (starting with count), with rerolls
- # and up to maxexplode explosions
- class ExplodingDieNumberDensity < Density
- def initialize(max,rerolls=[],count=1,maxexplode=10)
- super(0)
- @d.delete(0)
- @uniform=false
- if (rerolls.include?max)
- n=max - rerolls.size + 1
- @d[1]=Rational(n-1,n)
- for k in (2..maxexplode) do
- for r in (1..(k-1)) do
- @d[k]+=Rational(@d[r]*@d[k-r],n)
- end
- end
- @d[maxexplode+1]=1-@d.inject(:+)
- else
- n=max - rerolls.size
- for k in (1..maxexplode) do
- @d[k]=Rational(n-1,n**k)
- end
- @d[maxexplode+1]=Rational(1,n**(e-1))
- end
- self=([z]*count).inject(:+)
- # if we only limit the explosions of individual dices don't do the following command:
- delete_if { |k,v| k > maxexplode + 1}
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment