Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jmtaysom
Created March 20, 2018 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmtaysom/6d64d3f84a53a704762337662f196e8e to your computer and use it in GitHub Desktop.
Save jmtaysom/6d64d3f84a53a704762337662f196e8e to your computer and use it in GitHub Desktop.
Calculate the results of a fate roll in Shadow of the Demon Lord
from random import randint
def roll_fate(round=1, fate=0):
if fate == 3:
return ('unconsious', round)
roll = randint(1,7)
if roll == 6:
return ('lived', round)
elif roll == 1:
return roll_death(round)
else:
return roll_fate(round=round+1, fate=fate+1)
#return result
def roll_death(round):
roll = randint(1,7)
#result = None
if roll == 6:
return roll_fate(round=round+1)
elif roll == 1:
return ('died', round)
else:
return roll_death(round=round+1)
#return result
if __name__ == '__main__':
lived = 0
l_round = []
died = 0
d_round = []
koed = 0
k_round = []
iterations = 100000
for _ in range(iterations):
result = roll_fate()
if result[0] == 'lived':
lived += 1
l_round.append(result[1])
elif result[0] == 'died':
died += 1
d_round.append(result[1])
else:
koed += 1
k_round.append(result[1])
print(f'Lived: {lived} Died: {died}, KOed: {koed}')
print(f'Rounds to live {sum(l_round)/lived}')
print(f'Rounds to dying {sum(d_round)/died}')
print(f'Rounds to KO {sum(k_round)/koed}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment