Skip to content

Instantly share code, notes, and snippets.

@martin-martin
Created May 6, 2023 00:47
Show Gist options
  • Save martin-martin/1008796754d42ec2487874529304803f to your computer and use it in GitHub Desktop.
Save martin-martin/1008796754d42ec2487874529304803f to your computer and use it in GitHub Desktop.
import numpy as np
def create_deck():
RANKS = '2 3 4 5 6 7 8 9 10 J Q K A'.split()
SUITS = '♣ ♢ ♡ ♠'.split()
return np.array([r + s for s in SUITS for r in RANKS])
print(create_deck())
# ['2♣' '3♣' '4♣' '5♣' '6♣' '7♣' '8♣' '9♣' '10♣' 'J♣' 'Q♣' 'K♣' 'A♣' '2♢'
# '3♢' '4♢' '5♢' '6♢' '7♢' '8♢' '9♢' '10♢' 'J♢' 'Q♢' 'K♢' 'A♢' '2♡' '3♡'
# '4♡' '5♡' '6♡' '7♡' '8♡' '9♡' '10♡' 'J♡' 'Q♡' 'K♡' 'A♡' '2♠' '3♠' '4♠'
# '5♠' '6♠' '7♠' '8♠' '9♠' '10♠' 'J♠' 'Q♠' 'K♠' 'A♠']
@martin-martin
Copy link
Author

Or, if this is too overwhelming, you could make a selection of cards first. For example, the Austrian card game called Schnapsen is played with only 10 J Q K A:

>>> schnapsen_deck = stacked_deck[:,-5:]
>>> schnapsen_deck
array([['10♣', 'J♣', 'Q♣', 'K♣', 'A♣'],
       ['10♢', 'J♢', 'Q♢', 'K♢', 'A♢'],
       ['10♡', 'J♡', 'Q♡', 'K♡', 'A♡'],
       ['10♠', 'J♠', 'Q♠', 'K♠', 'A♠']], dtype='<U3')

With this deck, you'd (nearly) be back to the amount of elements that you're using in your examples, but it adds a bit of real-world meaning to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment