Last active
November 17, 2022 18:47
-
-
Save andytwoods/81be395fd4a44366e7fc6d9d9c77f675 to your computer and use it in GitHub Desktop.
dnd advantage vs regular vs disadvantage
This file contains hidden or 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
import random | |
from collections import Counter | |
simulations = 1000000 | |
def dice_roll(): | |
return random.randint(1, 20) | |
def show_outcome(nam, counter): | |
total = 0 | |
for key, val in counter.items(): | |
total += key * val | |
print(nam, round(total / simulations, 2)) | |
def do_run(): | |
adv_counter = Counter() | |
reg_counter = Counter() | |
dis_counter = Counter() | |
for sim in range(simulations): | |
outcome = dice_roll() | |
outcome2 = dice_roll() | |
adv_counter.update([max(outcome, outcome2), ]) | |
reg_counter.update([outcome]) | |
dis_counter.update([min(outcome, outcome2), ]) | |
show_outcome('advantage ', adv_counter) | |
show_outcome('regular ', reg_counter) | |
show_outcome('disadvantage', dis_counter) | |
do_run() | |
# advantage 13.82 | |
# regular 10.51 | |
# disadvantage 7.18 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment