A package for representing hands of cards (quite compactly)
This package defines three types:
Suit
uses 2 low bits of a UInt8
to represent four suits of cards: ♣, ♢, ♡, ♠.
Card
uses 6 low bits of a UInt8
to represent 64 possible card values:
Suit
(♣, ♢, ♡, ♠)Hand
uses 64 bits of a UInt64
to represent all possible hands (sets) of cards.
The design of having high and low aces and jokers allows hands from many different games to be represented in a single scheme, with consistent rank ordering. If you're representing hands from a game with aces high, use the A♣
, A♢
, A♡
, A♠
cards; if you're representing hands from a game with aces low, use the 1♣
, 1♢
, 1♡
, 1♠
cards instead.
julia> using Cards
julia> hand = rand(Hand)
Hand([2♣, 3♣, 6♣, 7♣, 8♣, 9♣, 2♢, 3♢, 4♢, 7♢, 10♢, J♢, A♢, 4♡, 5♡, 6♡, 7♡, Q♡, K♡, A♡, 4♠, 6♠, 9♠, K♠, A♠])
julia> 2♣ in hand
true
julia> 4♣ in hand
false
julia> A♣ in hand
false
julia> A♠ in hand
true
julia> ♡ ∩ hand
Hand([4♡, 5♡, 6♡, 7♡, Q♡, K♡, A♡])
julia> ♠ ∩ hand
Hand([4♠, 6♠, 9♠, K♠, A♠])
julia> length(♣ ∩ hand)
6