4 deck card game
-
I have pretty much only a basic idea how to code on pythonista, the modules help a lot, but I can’t seem to find a way to code a game with 4 separate decks of cards, that aren’t poker decks. It’s similar to cards against humanity, but different. If I could understand how to how the class function works to make, shuffle, and deal from a red, blue, yellow and white deck, and how to make the “cards” themselves which only contain text, I can get on to learning the ui function. Thanks in advance!
-
#! /usr/bin/env python3 from random import shuffle def make_card_deck(ranks=None, suits="CDHS") -> list: ranks = ranks or [str(n) for n in range(2, 11)] + list("JQKA") return [rank + suit for suit in suits for rank in ranks] if __name__ == "__main__": decks = {color: make_card_deck() for color in "blue red yellow white".split()} print(decks) shuffle(decks["blue"]) print(decks["blue"]) print(make_card_deck("iOS Linux macOS Windows".split(), ".app .exe .py".split()))
-
Hello, does this basic class from the excellent Fluent Python book help? It should support shuffling with
random.shuffle()
and you can iterate over it to deal cards.-Graham
and this sample usage, including sorting with a custom key "Spades high"
https://github.com/fluentpython/example-code/blob/3d74f0e18344c2d257e00b689f4c7fe25b974952/01-data-model/frenchdeck.doctest