Lesson 5 of 7 · 2 min
Play against it
# run locally: play.py, after training in the same file
def computer(card, h):
n = nodes.get(str(card) + h)
avg = n["total"] / n["total"].sum() if n else [0.5, 0.5]
return random.choices("pb", weights=avg)[0]
bank = 0
while True:
random.shuffle(deck)
h = ""
while payoff(deck, h) is None:
if len(h) % 2 == 0:
h += input(f"your card {deck[0]}, history '{h}'. p or b? ").strip()[:1] or "p"
else:
h += computer(deck[1], h)
p = payoff(deck, h) * (1 if len(h) % 2 == 0 else -1)
bank += p
print("history", h, "their card", deck[1], "you", p, "total", bank)