Skip to content

Instantly share code, notes, and snippets.

@sooop

sooop/e084_1.py Secret

Created Apr 21, 2021
Embed
What would you like to do?
from random import choice, randrange, shuffle
from utils import timeit
# fmt:off
rooms: list[str] = (
"GO", "A1", "CC1", "A2", "T1", "R1", "B1", "CH1", "B2", "B3", "JAIL", "C1", "U1",
"C2", "C3", "R2", "D1", "CC2", "D2", "D3", "FP", "E1", "CH2", "E2", "E3", "R3",
"F1", "F2", "U2", "F3", "G2J", "G1", "G2", "CC3", "G3", "R4", "CH3", "H1", "T2",
"H2"
)
deck_cc: list[str] = [""] * 14 + ["GO", "JAIL"]
deck_ch: list[str] = [""] * 6 + [
"GO", "JAIL", "C1", "E3", "H2", "R1", "Rn", "Rn", "Un", "-3"
]
# fmt:on
def run(faces=6, goes=10000):
cc_cards, ch_cards = deck_cc[:], deck_ch[:]
shuffle(cc_cards)
shuffle(ch_cards)
cc_ind, ch_ind = 0, 0
res = {}
d = 0
pos = 0
for _ in range(goes):
x, y = (1 + randrange(faces) for _ in range(2))
if x == y:
d += 1
if d == 3:
d = 0
pos = 10
res[pos] = res.setdefault(pos, 0) + 1
continue
res[pos] = res.setdefault(pos, 0) + 1
continue
else:
d = 0
pos = (pos + x + y) % 40
if rooms[pos].startswith("CH"):
# cdeck
card = ch_cards[cc_ind]
ch_ind = (ch_ind + 1) % 16
if card == "":
pass
elif card == "-3":
pos = (pos + 37) % 40
elif card == "Rn":
pos = ([room[0] for room in rooms] * 2).index("R", pos) % 40
elif card == "Un":
pos = ([room[0] for room in rooms] * 2).index("U", pos) % 40
else:
pos = rooms.index(card)
if rooms[pos].startswith('CC'):
# hdeck
card = cc_cards[ch_ind]
cc_ind = (cc_ind + 1) % 16
if card != "":
pos = rooms.index(card)
if rooms[pos] == "G2J":
pos = 10
res[pos] = res.setdefault(pos, 0) + 1
return res
@timeit
def main():
res = {}
s = run(6, 120_0000)
for k, v in s.items():
res[k] = res.get(k, 0) + v
t = sum(res.values())
ws = {k: v / t * 100 for k, v in res.items()}
ws = sorted(ws.items(), key=lambda x: x[1], reverse=True)[:3]
for w, v in ws:
print(f"{w:02d}-{rooms[w]}\t({v:.2f}%)")
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment