Skip to content

lethargilistic/spydes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spydes

Python3-exclusive playing cards in four suits, with and without jokers, provided as a library for your gaming pleasure.

It's time to let go of Legacy Python, but I'm not about to rip it out of someone else's project. I'm not a jerk.

How to use it

Card

A Card is a namedtuple with extensions for printing out to the screen. The tuple has two values, Suit and Value, which are intended to take their values from the enumerators documented elsewhere. However, strictly speaking, you're not required to use the enumerators. The pretty output extensions would no longer work, but you could redefine __str__ or use __repr__ for debugging if you want custom suits or values.

__str__()

Outputs two characters, representing the value and the suit. For example, "TC" would represent the 10 of Clubs and "AS" would represent the Ace of Spades (salute!).

unicard(vary_jokers=False)

Returns the Unicode character representing that playing card, using the unicard library. It also handles Jokers, which unicard does not.

There are 3 Unicode Joker characters, but the default is 🃏. If you would like to use more than one, you may set vary_jokers to True. The Jokers are differentiated by their Value, modulo 3.

Deck

You can instantiate a Deck() from which to draw(), cut(*weights), or shuffle().

Hand

A Hand is literally a Deck. It's an alias. It exists so that you can write more natural lines like:

deck = Deck()
player_one_hand = Hand() #not Deck()
player_two_hand = Hand() #not Deck()

Suit

An enumerator for the playing card Suit that includes the standard four as CLUB, SPADE, DIAMOND, and HEART. In addition, it also allows you to mark Jokers with JOKER.

A generous assortment of alternative names for the suits are available, but if there's a nickname that is shared between two suits, that has been omitted. All of these nicknames are singular, not plural.

all_suits

For your convenience, spydes also provides a list called all_suits that includes only the four suits, without the Joker. You may iterate through this if you want to do some aggregate operation with just the suits.

for suit in standard_suits:
    print(suit)
#Suit.SPADE
#Suit.HEART
#Suit.DIAMOND
#Suit.CLUB

Value

An enumerator for the playing card Suit that includes the thirteen standard values by name.

A generous assortment of alternative names for the values are available, but if there's a nickname that is shared between two values, that has been omitted. For example, there is no Value.SHARP_TOP because that refers to Aces and Fours. All of these nicknames are singular, not plural.

all_values

For your convenience, spydes also provides a list called all_values. You can iterate through it to get all the suits, in numerical order. It mostly exists for consistency with all_suits

How to license it

MIT License

Releases

No releases published

Packages

No packages published

Languages