Skip to content

Instantly share code, notes, and snippets.

@paulhendricks
Last active July 10, 2019 06:06
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 paulhendricks/db3874c2d9c9996fd4f213aadb426540 to your computer and use it in GitHub Desktop.
Save paulhendricks/db3874c2d9c9996fd4f213aadb426540 to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
import numpy as np
# settings
n_iterations = 100000
# great sword
initiative = np.random.randint(1, 21, size=(n_iterations,)) + 2
damage = np.random.randint(1, 7, size=(2, n_iterations)).sum(axis=0) + 2
enemy_armor_classes = list(range(26))
average_great_sword_damage = []
for enemy_armor_class in enemy_armor_classes:
mask = initiative < enemy_armor_class
modified_damage = damage
modified_damage[mask] = 0
average_great_sword_damage.append(modified_damage.mean())
print('Armor Class: ', enemy_armor_class,
'Resulting Damage:', modified_damage.mean(),
'+-', modified_damage.std())
# great axe
initiative = np.random.randint(1, 21, size=(n_iterations,)) + 2
damage = np.random.randint(1, 13, size=(n_iterations,)) + 2
average_great_axe_damage = []
for enemy_armor_class in enemy_armor_classes:
mask = initiative < enemy_armor_class
modified_damage = damage
modified_damage[mask] = 0
average_great_axe_damage.append(modified_damage.mean())
print('Armor Class: ', enemy_armor_class,
'Resulting Damage:', modified_damage.mean(),
'+-', modified_damage.std())
average_great_sword_damage = np.asarray(average_great_sword_damage)
average_great_axe_damage = np.asarray(average_great_axe_damage)
# show visual
plt.scatter(enemy_armor_classes, average_great_sword_damage, label='Great Sword')
plt.scatter(enemy_armor_classes, average_great_axe_damage, label='Great Axe')
plt.title('Average Effective Damage Against Enemies (10,000 random samples)')
plt.xlabel('Enemy Armor Class')
plt.ylabel('Average Damage (inititative included)')
plt.xticks(list(range(0, 26, 5)))
plt.yticks(list(range(11)))
plt.legend()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment