Skip to content

Instantly share code, notes, and snippets.

@tkphd
Created January 22, 2023 23:19
Show Gist options
  • Save tkphd/adea30c2ae9254ae5f90834fdefc8f82 to your computer and use it in GitHub Desktop.
Save tkphd/adea30c2ae9254ae5f90834fdefc8f82 to your computer and use it in GitHub Desktop.
Random card generator for The Quiet Year
#!/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