Created
May 28, 2012 07:38
-
-
Save BlckKnght/2817882 to your computer and use it in GitHub Desktop.
Face to Face rolls using Neutronicus's formulas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def binomial_coefficient(n, k): | |
"""Returns the binomial coefficient, "n choose k".""" | |
if k > n-k: # if k is greater than n/2, swap it for n-k which will be | |
k = n-k | |
result = 1; | |
for i in range(k): # loop from 0 to k-1 | |
result *= (n-i) / (i+1) # multiply in one term of the result | |
return result | |
def neutronicus_coef(B1, b1, B2, b2, c, k): | |
choose = binomial_coefficient # shorthand | |
if B1 <= B2: | |
l = 1 | |
else: | |
l = 0 | |
if k == 0: | |
return choose(b1,c)*(20-B1)**(b1-c)*(20-l)**b2 | |
result = 0 | |
for m in range(1, B1): | |
for M in range(1, m-l+1): | |
result += choose(b1, c)*(b1-c)*b2*\ | |
choose(b1-c-1,k-1)*(B1-m)**(k-1)*\ | |
((20-B1)+M-l)**(b1-c-k)*\ | |
((20-B2)+M)**(b2-1) | |
return result | |
def neutronicus_MvsN(defender_dice, defender_target, | |
attacker_dice, attacker_target): | |
denom = 20**(defender_dice+attacker_dice) | |
defender_results = [[neutronicus_coef(defender_target, defender_dice, | |
attacker_target, attacker_dice, | |
crits, hits-crits) / denom | |
for crits in range(0, hits+1)] | |
for hits in range(1, defender_dice+1)] | |
return defender_results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment