login
Tarokka reader posted: Wed 2023-05-31 20:23:32 tags: n/a
If you only want the "card name" (e.g. One of Coins, Master of Glyphs, etc.) then you can quickly assemble the "common deck" from an iterable comprehension like:
def make_common_deck():
    deck = set()
    suits = ["Coins", "Glyphs", "Swords", "Stars"]
    ranks = []
    # no Aces, they're ones
    for i in range(1, 10):
        ranks.append(str(i))

    # no tens, they're Masters
    ranks.append("Master")

    for suit in suits:
        cards = {f'{rank} of {suit}' for rank in ranks}
        deck.update(cards)

    return deck

....But if the automation is to include the "flavor" name (e.g. the 1 of Swords is "Avenger", 2 of Swords is "Paladin", etc.) and interpretation, for example "The Four of Coins means the treasure lies near a cask that once contained the finest wine, of which not a drop remains" - then there are a few different ways to pack that all into one program. The least efficient is to store a dictionary with card identifers (1 of Swords, 2 of Swords, ...) and comparison-search a dictionary for associated data for each card pulled. (Inefficient, because you have to duplicate the card names.) The messiest, but most efficient, is to hard-code all the data right within the program so that the dict is assembled in memory the same way every time, and each card pull .pop() will consist of a complete record for its place in a reading.

The middle path (programatically tidy, and more efficient than searching the dict for each match) is to store associated data in external files, in the same order as the comprehensions fills the deck arrays, and build the dicts in memory on each run. With a much larger data set we would have to do it differently but on modern casual computing environments the resource load is relatively trivial: kilobytes on machines with gigabytes of memory capacity.