PlayingCards.jl

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:

using PlayingCards
@show card = A♡
@show string(card)
@show suit(A♡)
@show rank(A♠)
@show high_value(A♢)
@show high_value(J♣)
@show low_value(A♡)
nothing
card = A♡ = A♡
string(card) = "A♡"
suit(A♡) = ♡
rank(A♠) = 1
high_value(A♢) = 14
high_value(J♣) = 11
low_value(A♡) = 1

Decks

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

using PlayingCards
@show deck = ordered_deck()

shuffle!(deck)

@show hand = pop!(deck, 2)

@show deck
nothing
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♢

hand = pop!(deck, 2) = (Q♣, A♢)
deck = 6♠ 5♠ A♠ J♢ 9♡ Q♠ 3♠ 7♠ T♣ J♠ 4♣ 4♢ 4♡
6♢ 8♠ A♡ J♡ 8♡ 7♡ 2♠ 9♠ 6♡ T♠ 5♡ 7♢ 5♣
J♣ 3♢ 2♢ K♠ 8♢ 9♢ A♣ Q♢ 5♢ K♡ K♢ 2♡ 6♣
4♠ 3♣ T♢ 3♡ T♡ Q♡ 7♣ 2♣ K♣ 9♣ 8♣