Skip to content

Instantly share code, notes, and snippets.

@nishio
Last active April 16, 2022 09:39
Show Gist options
  • Save nishio/9477ac3fb3ee7f904257eec6e3ca2832 to your computer and use it in GitHub Desktop.
Save nishio/9477ac3fb3ee7f904257eec6e3ca2832 to your computer and use it in GitHub Desktop.
from random import shuffle
from dominion_avecoin import hand_to_coins
from collections import defaultdict
NUM_TRIAL = 10000
def draw(deck, N=5):
tmp = list(deck)
shuffle(tmp)
draw, rest = tmp[:N], tmp[N:]
return draw, rest
def calc(initial_deck, to_return=False, start_action=1):
# print(initial_deck)
stat_coins = defaultdict(int)
for _i in range(NUM_TRIAL):
hand, deck = draw(initial_deck)
action = start_action
while action > 0:
# print(hand)
action -= 1
if "V" in hand:
hand.remove("V")
tmp, deck = draw(deck, 1)
hand += tmp
action += 2
continue
if "S" in hand:
hand.remove("S")
tmp, deck = draw(deck, 3)
hand += tmp
continue
# no action card
action += 1
break
# print(hand)
coins = hand_to_coins(hand)
# print(coins)
stat_coins[coins] += 1
# print(stat_coins)
over_8 = 0
for k in stat_coins:
if k >= 8:
over_8 += stat_coins[k]
p = over_8 / NUM_TRIAL * 100
# print(f"{p:.0f}%")
# if to_return:
# return stat_coins
return p
# calc("1111111eee2SVS")
# calc("1111111eee2SVSVS")
# calc("1111111eee2SVSVSVS")
# calc("1111111eee2SVSVSVSVS")
# calc("1111111eee2SVSVSVSVSVS")
# stat = calc("1111111eee2SVSVSVSVSVSVS", to_return=True)
# print(", ".join([
# (f"{k}: {100 * stat[k] / NUM_TRIAL:.0f}%")
# for k in sorted(stat)]))
# for v in range(21):
# row = []
# for s in range(21):
# p = calc("1111111eee2" + "V" * v + "S" * s)
# row.append(f"{p:2.0f}%")
# print(f"v:{v:2d}", ", ".join(row))
# for v in range(11):
# row = []
# for s in range(11):
# p = calc("2222pppp" + "V" * v + "S" * s)
# row.append(f"{p:2.0f}%")
# print(f"v:{v:2d}", ", ".join(row))
for v in range(11):
row = []
for s in range(11):
p = calc("1111111eee2" + "V" * v + "S" * s, start_action=4)
row.append(f"{p:2.0f}%")
print(f"v:{v:2d}", ", ".join(row))
# prob. to buy province
1111111eee2SVS
6%
1111111eee2SVSVS
15%
1111111eee2SVSVSVS
26%
1111111eee2SVSVSVSVS
38%
1111111eee2SVSVSVSVSVS
48%
1111111eee2SVSVSVSVSVSVS
56%
# p = calc("1111111eee2" + "V" * v + "S" * s)
v: 0 0%, 1%, 1%, 0%, 0%, 0%, 0%, 0%, 0%, 0%, 0%, 0%, 0%, 0%, 0%, 0%, 0%, 0%, 0%, 0%, 0%
v: 1 0%, 1%, 6%, 4%, 3%, 2%, 1%, 1%, 1%, 0%, 0%, 0%, 0%, 0%, 0%, 0%, 0%, 0%, 0%, 0%, 0%
v: 2 0%, 1%, 7%, 14%, 16%, 12%, 8%, 6%, 4%, 2%, 2%, 1%, 1%, 0%, 0%, 0%, 0%, 0%, 0%, 0%, 0%
v: 3 0%, 1%, 9%, 23%, 26%, 25%, 22%, 17%, 13%, 9%, 6%, 4%, 3%, 2%, 1%, 1%, 1%, 0%, 0%, 0%, 0%
v: 4 0%, 1%, 10%, 27%, 37%, 38%, 36%, 32%, 26%, 22%, 16%, 12%, 8%, 6%, 4%, 3%, 2%, 1%, 1%, 1%, 1%
v: 5 0%, 1%, 12%, 34%, 45%, 48%, 47%, 45%, 40%, 34%, 29%, 24%, 20%, 15%, 11%, 8%, 7%, 4%, 3%, 2%, 2%
v: 6 0%, 1%, 13%, 36%, 51%, 56%, 57%, 55%, 51%, 48%, 43%, 37%, 32%, 27%, 22%, 18%, 14%, 11%, 8%, 6%, 4%
v: 7 0%, 1%, 13%, 39%, 54%, 62%, 64%, 65%, 60%, 59%, 54%, 50%, 44%, 40%, 35%, 29%, 25%, 20%, 17%, 13%, 10%
v: 8 0%, 1%, 14%, 40%, 58%, 65%, 69%, 69%, 69%, 66%, 63%, 58%, 55%, 51%, 46%, 42%, 36%, 32%, 28%, 23%, 19%
v: 9 0%, 1%, 14%, 42%, 59%, 70%, 73%, 74%, 75%, 73%, 71%, 67%, 64%, 60%, 55%, 52%, 48%, 43%, 38%, 34%, 30%
v:10 0%, 1%, 14%, 43%, 60%, 71%, 76%, 78%, 78%, 77%, 75%, 73%, 71%, 67%, 64%, 60%, 56%, 53%, 48%, 44%, 40%
v:11 0%, 1%, 15%, 43%, 62%, 73%, 78%, 81%, 81%, 80%, 80%, 78%, 76%, 73%, 70%, 68%, 64%, 61%, 57%, 54%, 49%
v:12 0%, 1%, 14%, 43%, 63%, 74%, 80%, 83%, 84%, 83%, 82%, 82%, 79%, 77%, 75%, 73%, 69%, 67%, 63%, 61%, 57%
v:13 0%, 1%, 14%, 43%, 64%, 75%, 81%, 84%, 85%, 86%, 86%, 85%, 83%, 81%, 80%, 78%, 75%, 73%, 69%, 67%, 64%
v:14 0%, 1%, 14%, 44%, 64%, 75%, 82%, 85%, 86%, 87%, 88%, 87%, 86%, 85%, 83%, 81%, 79%, 76%, 75%, 72%, 70%
v:15 0%, 1%, 14%, 44%, 65%, 76%, 83%, 86%, 88%, 89%, 89%, 88%, 88%, 87%, 85%, 84%, 82%, 80%, 78%, 77%, 74%
v:16 0%, 1%, 14%, 44%, 65%, 76%, 83%, 86%, 89%, 90%, 90%, 90%, 89%, 88%, 87%, 86%, 85%, 83%, 81%, 79%, 79%
v:17 0%, 1%, 14%, 44%, 65%, 77%, 83%, 87%, 90%, 91%, 92%, 91%, 91%, 90%, 89%, 88%, 87%, 85%, 84%, 83%, 81%
v:18 0%, 1%, 14%, 45%, 64%, 78%, 84%, 89%, 90%, 92%, 92%, 92%, 92%, 91%, 91%, 89%, 89%, 88%, 87%, 85%, 83%
v:19 0%, 1%, 15%, 45%, 65%, 78%, 84%, 88%, 90%, 92%, 93%, 93%, 92%, 92%, 92%, 91%, 90%, 89%, 88%, 86%, 85%
v:20 0%, 1%, 15%, 45%, 65%, 78%, 84%, 88%, 91%, 92%, 93%, 93%, 93%, 94%, 92%, 92%, 91%, 90%, 89%, 89%, 87%
# p = calc("2222pppp" + "V" * v + "S" * s)
v: 0 7%, 30%, 24%, 18%, 13%, 9%, 6%, 5%, 3%, 3%, 2%
v: 1 7%, 26%, 41%, 43%, 29%, 20%, 14%, 10%, 7%, 6%, 4%
v: 2 7%, 26%, 51%, 52%, 46%, 41%, 34%, 24%, 16%, 12%, 9%
v: 3 7%, 28%, 56%, 63%, 61%, 57%, 48%, 40%, 34%, 27%, 19%
v: 4 7%, 30%, 60%, 70%, 70%, 68%, 62%, 55%, 49%, 42%, 35%
v: 5 7%, 30%, 62%, 75%, 78%, 76%, 71%, 67%, 62%, 55%, 49%
v: 6 7%, 30%, 64%, 78%, 81%, 81%, 79%, 76%, 71%, 66%, 62%
v: 7 7%, 29%, 65%, 79%, 84%, 85%, 83%, 82%, 78%, 74%, 70%
v: 8 7%, 31%, 66%, 80%, 86%, 88%, 87%, 86%, 83%, 81%, 78%
v: 9 7%, 31%, 67%, 82%, 87%, 89%, 89%, 88%, 87%, 85%, 82%
v:10 7%, 30%, 67%, 82%, 88%, 91%, 91%, 90%, 89%, 89%, 86%
# p = calc("1111111eee2" + "V" * v + "S" * s, start_action=4)
v: 0 0%, 1%, 14%, 45%, 67%, 78%, 86%, 85%, 71%, 55%, 43%
v: 1 0%, 1%, 15%, 45%, 65%, 79%, 85%, 86%, 84%, 80%, 72%
v: 2 0%, 1%, 15%, 46%, 66%, 78%, 85%, 88%, 89%, 88%, 84%
v: 3 0%, 1%, 15%, 45%, 66%, 78%, 86%, 90%, 92%, 92%, 91%
v: 4 0%, 1%, 15%, 46%, 66%, 78%, 86%, 89%, 92%, 93%, 94%
v: 5 0%, 1%, 15%, 45%, 66%, 78%, 86%, 90%, 93%, 95%, 95%
v: 6 0%, 1%, 15%, 45%, 66%, 78%, 86%, 91%, 93%, 95%, 96%
v: 7 0%, 1%, 15%, 46%, 66%, 79%, 86%, 91%, 93%, 95%, 96%
v: 8 0%, 1%, 15%, 45%, 65%, 78%, 86%, 91%, 93%, 96%, 96%
v: 9 0%, 1%, 14%, 45%, 66%, 78%, 86%, 91%, 93%, 95%, 96%
v:10 0%, 1%, 15%, 45%, 66%, 80%, 86%, 90%, 93%, 95%, 97%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment