PlayingCards.jl

A package for representing playing cards for card games.
Popularity
14 Stars
Updated Last
2 Years Ago
Started In
March 2021

PlayingCards.jl

Docs Build docs build
Documentation dev
GHA CI gha ci
Code Coverage codecov
Bors enabled bors

A package for representing playing cards for card games (for a standard deck of fifty two).

Cards

A playing Card is consists of a suit (♣,♠,♡,♢) and a rank:

  • Rank(N::Int) where 1 ≤ N ≤ 13 where
  • N = 1 represents an Ace (which can have high or low values via high_value and low_value)
  • N = 11 represents a Jack
  • N = 12 represents a Queen
  • N = 13 represents a King

The value of the rank can be retrieved from high_value and low_value:

  • high_value(c::Card) == low_value(c::Card) == c.rank
  • high_value(::Card) = 14 for Ace
  • low_value(::Card) = 1 for Ace

Cards have convenience constructors and methods for extracting information about them:

julia> using PlayingCards

julia> card = A♡
A♡

julia> string(card)
"A♡"

julia> suit(A♡)
Heart()

julia> rank(A♠)
Ace()

julia> high_value(A♢)
14

julia> high_value(J♣)
11

julia> low_value(A♡)
1

Decks

A Deck is a struct with a Vector of Cards, which has a few convenience methods:

julia> using PlayingCards

julia> deck = ordered_deck()
A♣ 2♣  3♣  4♣  5♣  6♣  7♣  8♣  9♣  T♣  J♣  Q♣  K♣
A♠ 2♠  3♠  4♠  5♠  6♠  7♠  8♠  9♠  T♠  J♠  Q♠  K♠
A♡ 2♡  3♡  4♡  5♡  6♡  7♡  8♡  9♡  T♡  J♡  Q♡  K♡
A♢ 2♢  3♢  4♢  5♢  6♢  7♢  8♢  9♢  T♢  J♢  Q♢  K♢


julia> shuffle!(deck)

julia> hand = pop!(deck, 2)
(5♣, 8♢)

julia> deck
Q♣  T♣  5♢  K♠  J♢  4♢  T♡  K♢  2♠  5♠  2♡  8♣  8♠
K♣  T♠  A♣  Q♠  Q♢  2♢  7♣  6♣  J♡  9♠  6♢  A♢  7♠
A♡  7♡  3♢  3♣  7♢  J♠  5♡  4♡  9♢  4♣  3♠  J♣  6♡
9♡  6♠  T♢  3♡  A♠  8♡  K♡  2♣  4♠  Q♡  9♣

Related packages

Package Development status Purpose
PlayingCards.jl Perhaps stable Representing cards
PokerHandEvaluator.jl Perhaps stable Comparing any two 5-7 card hands
TexasHoldem.jl Likely changes needed Simulating multi-player games of TexasHoldem
PokerBots.jl very early development Battling bots with prescribed (or learned) strategies
PokerGUI.jl very early development Visualizing TexasHoldem games via a GUI

Acknowledgements

Some ideas used here were inspired by