Guest User

Untitled

a guest
Sep 26th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # density for the _number_ of rolled exploding dices (starting with count), with rerolls
  2. # and up to maxexplode explosions
  3. class ExplodingDieNumberDensity < Density
  4.   def initialize(max,rerolls=[],count=1,maxexplode=10)
  5.     super(0)
  6.     @d.delete(0)
  7.     @uniform=false
  8.  
  9.     if (rerolls.include?max)
  10.       n=max - rerolls.size + 1
  11.       @d[1]=Rational(n-1,n)
  12.       for k in (2..maxexplode) do
  13.         for r in (1..(k-1)) do  
  14.           @d[k]+=Rational(@d[r]*@d[k-r],n)
  15.         end
  16.       end  
  17.       @d[maxexplode+1]=1-@d.inject(:+)
  18.     else
  19.       n=max - rerolls.size
  20.       for k in (1..maxexplode) do
  21.         @d[k]=Rational(n-1,n**k)
  22.       end
  23.       @d[maxexplode+1]=Rational(1,n**(e-1))
  24.     end
  25.  
  26.     self=([z]*count).inject(:+)
  27.     # if we only limit the explosions of individual dices don't do the following command:
  28.     delete_if { |k,v| k > maxexplode + 1}
  29.   end
  30. end
Advertisement
Add Comment
Please, Sign In to add comment