Skip to content

Instantly share code, notes, and snippets.

@jampekka
Last active Nov 4, 2021
Embed
What would you like to do?
Simple The Mind type game
import random
import selectors
import sys
total_cards = 100
cards_per_player = 3
deck = list(range(1, total_cards + 1))
random.shuffle(deck)
player_hand, deck = deck[:cards_per_player], deck[cards_per_player:]
machine_hand, deck = deck[:cards_per_player], deck[cards_per_player:]
player_hand.sort()
machine_hand.sort()
top_card = 0
machine_seconds_per_point = 0.5
sel = selectors.DefaultSelector()
sel.register(sys.stdin, selectors.EVENT_READ)
while player_hand and machine_hand:
print(f"Table: {top_card}. Your hand: {player_hand}. Press enter to play {player_hand[0]}.")
machine_diff = machine_hand[0] - top_card
machine_wait = machine_diff*machine_seconds_per_point
event = sel.select(machine_wait)
if not event:
card, *machine_hand = machine_hand
if card > player_hand[0]:
print(f"Machine played {card}, but you have {player_hand[0]}! Sorry!")
break
else:
top_card = card
print(f"Machine plays {card}.")
else:
sys.stdin.readline()
card, *player_hand = player_hand
if card > machine_hand[0]:
print(f"You played {card}, but the machine has {machine_hand[0]}! Sorry!")
break
else:
top_card = card
print(f"You play {card}.")
else:
print(f"Yay, you won! Machine hand: {machine_hand}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment