Cards.jl Save

A package for representing hands of cards (quite compactly)

Project README

Cards

Build Status Coverage Status codecov.io

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:

    • 2 bits for the Suit (♣, ♢, ♡, ♠)
    • 4 bits for the rank from 0-15, meaning:
      • 0 – low joker
      • 1 – low ace
      • 2-10 – number cards
      • 11-13 – jack, queen, king
      • 14 – high ace
      • 15 – high joker
  • 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.

Example usage:

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
Open Source Agenda is not affiliated with "Cards.jl" Project. README Source: StefanKarpinski/Cards.jl
Stars
46
Open Issues
0
Last Commit
3 years ago

Open Source Agenda Badge

Open Source Agenda Rating