Last active
June 13, 2021 21:11
-
-
Save MattUebel/c5a70f36f97b27afa64e795fbc5f3295 to your computer and use it in GitHub Desktop.
simulates an execution of Tasha's Hideous Laughter 100,000 times
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
import random | |
NOUN_LIST = ["apple", "cow", "tree", "hat", "dog", "magic", "bolt", "arrow"] | |
ADJECTIVE_LIST = ["red", "big", "small", "good", "bad", "old", "new", "young"] | |
CARD_TYPES = ["creature", "land", "spell"] | |
CARD_TYPE_WEIGHTS = (30, 50, 30) | |
class MagicCard: | |
def __init__(self): | |
self.card_type = random.choices(CARD_TYPES, weights=CARD_TYPE_WEIGHTS)[0] | |
if self.card_type in ["creature", "spell"]: | |
self.card_name = ( | |
random.choice(ADJECTIVE_LIST) + " " + random.choice(NOUN_LIST) | |
) | |
self.cost = random.choices(range(1, 7), weights=(20, 30, 50, 30, 5, 1))[0] | |
else: | |
self.card_name = "land" | |
self.cost = 0 | |
self.power, self.toughness = ( | |
self.random_pt() if self.card_type == "creature" else (None, None) | |
) | |
def random_pt(self): | |
return random.choice(range(1, 8)), random.choice(range(1, 8)) | |
class MagicDeck: | |
def __init__(self): | |
self.discard = [] | |
self.cards = [] | |
while len(self.cards) < 60: | |
self.cards.append(MagicCard()) | |
def add_card(self, card): | |
self.cards.append(MagicCard()) | |
def shuffle(self): | |
random.shuffle(self.cards) | |
def draw(self): | |
return self.cards.pop() | |
def discard_card(self, card): | |
self.discard.append(card) | |
def get_discard(self): | |
return self.discard | |
def get_cards(self): | |
return self.cards | |
def land_count(self): | |
return len([c for c in self.cards if c.card_type == "land"]) | |
def avg_mana_cost(self): | |
return sum([c.cost for c in self.cards]) / len(self.cards) | |
if __name__ == "__main__": | |
def run_trial(): | |
deck = MagicDeck() | |
total_mana_cost = 0 | |
total_cards_exiled = 0 | |
while total_mana_cost < 20: | |
drawn_card = deck.draw() | |
total_cards_exiled += 1 | |
total_mana_cost += drawn_card.cost | |
return (deck.avg_mana_cost(), deck.land_count(), total_cards_exiled) | |
trials = 100000 | |
results = [] | |
for i in range(trials): | |
results.append(run_trial()) | |
avg_mana_cost = sum([r[0] for r in results]) / trials | |
land_count = sum([r[1] for r in results]) / trials | |
cards_exiled = sum([r[2] for r in results]) / trials | |
print( | |
f"Average mana cost: {avg_mana_cost}" | |
+ f"\nLand count: {land_count}" | |
+ f"\nCards exiled: {cards_exiled}" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example output: