Created
January 22, 2023 23:19
-
-
Save tkphd/adea30c2ae9254ae5f90834fdefc8f82 to your computer and use it in GitHub Desktop.
Random card generator for The Quiet Year
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
#!/usr/bin/python3 | |
# -*- coding: utf-8 -*- | |
about = """ | |
A random card generator for The Quiet Year, which ends when ๐ฎ is drawn. | |
""" | |
fleet = """ | |
short game: remove 5 cards from each suit; drop ๐ but keep ๐ฎ | |
""" | |
from argparse import ArgumentParser | |
import random | |
import sys | |
try: | |
from rich import print | |
except ImportError: | |
pass | |
def get_suit(a): | |
# simple range(a, a+13) includes the "cup" as card 11 and drops the king | |
return [chr(a+x) for x in list(range(0, 11)) + list(range(12, 14))] | |
deck = { | |
"Spring": get_suit(0x1f0b1), # '๐ฑ' .. '๐พ' | |
"Summer": get_suit(0x1f0c1), # '๐' .. '๐' | |
"Autumn": get_suit(0x1f0d1), # '๐' .. '๐' | |
"Winter": get_suit(0x1f0a1), # '๐ก' .. '๐ฎ' | |
} | |
parser = ArgumentParser( | |
prog = "the-quiet-year", | |
description = about, | |
epilog = "Visit <https://buriedwithoutceremony.com/the-quiet-year> for details!" | |
) | |
parser.add_argument( | |
'-f', | |
'--fleeting', | |
action='store_true', | |
help=fleet, | |
) | |
parser.add_argument( | |
'-p', | |
'--print', | |
action='store_true', | |
help="print the deck and exit", | |
) | |
args = parser.parse_args() | |
if args.fleeting: | |
print("~ The Fleeting Year ~\n") | |
deck["Summer"].remove("๐") | |
for suit, cards in deck.items(): | |
deck[suit] = sorted(random.sample(cards, k=7)) | |
if not "๐ฎ" in deck["Winter"]: | |
deck["Winter"][-1] = "๐ฎ" | |
else: | |
print("~ The Quiet Year ~\n") | |
if args.print: | |
for season, suit in deck.items(): | |
print("{}: {}".format(season, suit)) | |
sys.exit() | |
if not "๐ฎ" in deck["Winter"]: | |
raise RuntimeError("King of Spades missing from the Winter suit. Unable to proceed.") | |
sys.exit(1) | |
if args.fleeting and "๐" in deck["Summer"]: | |
raise RuntimeError("King of Diamonds found in the Summer suit. Unable to proceed.") | |
sys.exit(1) | |
z = "" | |
for season, suit in deck.items(): | |
z = input("{} has begun.\n โ to draw a card, q to exit".format(season)) | |
if z == "q" or z == "Q": | |
sys.exit() | |
random.shuffle(suit) | |
for card in suit: | |
if (season == "Winter") and (card == "๐ฎ"): | |
print("{} The Frost Shepherds are here!".format(card)) | |
print("~ The Quiet Year has ended ~") | |
sys.exit() | |
z = input(" {} ".format(card)) | |
if z == "q" or z == "Q": | |
sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment