Skip to content

Instantly share code, notes, and snippets.

@AsteriskAmpersand
Created October 31, 2023 19:05
Show Gist options
  • Save AsteriskAmpersand/17bf7a84a0df4c303c14600aafe51cda to your computer and use it in GitHub Desktop.
Save AsteriskAmpersand/17bf7a84a0df4c303c14600aafe51cda to your computer and use it in GitHub Desktop.
Calculates odds of dying given toughness and diehard
import numpy as np
def makeMatrix(wound,toughness = False,diehard = False, remake = True):
deathvalue = 5 + diehard
m = [[0 for j in range(deathvalue)] for i in range(deathvalue)]
dieroll = [i for i in range(1,21)]
m[0][0] = 1.0
for i in range(1,deathvalue-1):
critSuccess = len(list(filter(lambda d: d == 20,dieroll)))
success = len(list(filter(lambda d: d!=20 and d >= (10+i-toughness),dieroll)))
cFs = list(filter(lambda d: d==1 or d - (10+i-toughness) <= -10,dieroll))
critFail = len(cFs)
fail = len(list(filter(lambda d:(d < (10+i-toughness)) and (d not in cFs) ,dieroll)))
#print(critSuccess,success,fail,critFail)
m[i][max(0,i-2)] += critSuccess/20
m[i][max(0,i-1)] += success/20
m[i][min(deathvalue-1,i+1+wound*remake)] += fail/20
m[i][min(deathvalue-1,i+2+wound*remake)] += critFail/20
m[deathvalue-1][deathvalue-1] = 1
return np.matrix(m).transpose()
def calcSurvival(toughness=False,diehard=False,remake=True):
bases = []
for wound in range(4):
M = makeMatrix(wound,toughness,diehard,remake)
cnv = M ** 100000
bases.append(cnv[0,wound+1])
#print(cnv[0,wound+1])
return bases
def rulesetCalc(remake = True):
ruleMat = []
bases = calcSurvival(remake = remake)
ruleMat.append(bases)
toughness = calcSurvival(toughness = True, remake = remake)
ruleMat.append(toughness)
diehard = calcSurvival(diehard = True, remake = remake)
ruleMat.append(diehard)
dietough = calcSurvival(toughness = True, diehard = True, remake = remake)
ruleMat.append(dietough)
return ruleMat
remakeChances = rulesetCalc(remake = True)
baseChances = rulesetCalc(remake = False)
#Pretty Print
feats = ["Base","Toughness","Diehard","Both"]
header = '''Feats | 0 | 1| 2 | 3
:--|:--:|:--:|:--:|--:'''
for row in baseChances:
print(" |" + " | ".join(("%.1f"%(column*100) for column in row)))
print()
for row in remakeChances:
print(" |" + " | ".join(("%.1f"%(column*100) for column in row)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment