Created
May 30, 2018 22:50
-
-
Save dwreeves/bc89c070be73b689a26b69ebd4eff7d7 to your computer and use it in GitHub Desktop.
MTG Necropotence Utility Curve
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
from random import shuffle | |
import csv | |
############################################################################### | |
## PARAMETERS | |
############################################################################### | |
# STARTING HANDS | |
# Cards are ordinally ranked from 1 (best) to 99 (worst) | |
HAND1 = [7, 20, 34, 60] | |
HAND2 = [7, 20, 34, 60, 97, 98, 99] | |
HAND3 = [7, 20, 34, 60, 1, 3] | |
HAND4 = [12, 15, 17, 19, 30, 60] | |
HAND5 = [99, 98, 97, 96, 95, 94, 93] | |
HAND6 = [1, 2, 3, 4, 5, 6] | |
HANDS = [HAND1, HAND2, HAND3, HAND4, HAND5, HAND6] | |
# NUMBER OF TRIALS | |
TRIALS = 10000 | |
############################################################################### | |
## UTILITY FUNCTIONS | |
############################################################################### | |
def utility_func1(cards): | |
u = 0 | |
for c in cards: | |
u += 100-min(c, 75) | |
return u | |
def utility_func2(cards): | |
u = 0 | |
for c in cards: | |
if c == 1: | |
u += 200 | |
elif c in [2, 3]: | |
u += 150 | |
else: | |
u += 100-min(c, 75) | |
return u | |
def utility_func3(cards): | |
u = 0 | |
for c in cards: | |
if c == 1: | |
u += 200 | |
elif c in [2, 3]: | |
u = 100 | |
elif c > 70: | |
u += 0 | |
else: | |
u += 80 - c | |
return u | |
############################################################################### | |
## MODEL | |
############################################################################### | |
def run_trials(utility_func=None, hands=None, trials=None): | |
run_avg = {} | |
for h, hand in enumerate(hands): | |
deck = [i for i in range(1, 100) if i not in hand] | |
run_avg[h] = {i : 0 for i in range(40)} | |
run_avg[h][0] = utility_func(hand) | |
for trial in range(trials): | |
shuffled_deck = deck | |
shuffle(shuffled_deck) | |
hand_size = len(hand) | |
selection = [i for i in hand] | |
for x in range(1, 40): | |
# x is the amount you pay to Necro. | |
selection.append(shuffled_deck[x-1]) | |
selection.sort() | |
rng = min(7, hand_size + x) | |
run_avg[h][x] = (run_avg[h][x]*trial + utility_func(selection[:rng]))/(trial+1) | |
with open('necro.csv', 'w') as f: | |
writer = csv.writer(f) | |
writer.writerows([[j for i, j in run_avg[h].items()] for h in run_avg]) | |
if __name__ == '__main__': | |
run_trials(utility_func=utility_func3, hands=HANDS, trials=TRIALS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment