Skip to content

charleskawczynski/PlayingCards.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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♣ 23456789♣  T♣  J♣  Q♣  K♣
A♠ 23456789♠  T♠  J♠  Q♠  K♠
A♡ 23456789♡  T♡  J♡  Q♡  K♡
A♢ 23456789♢  T♢  J♢  Q♢  K♢


julia> shuffle!(deck)

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

julia> deck
Q♣  T♣  5♢  K♠  J♢  4♢  T♡  K♢  25288♠
K♣  T♠  A♣  Q♠  Q♢  276♣  J♡  96♢  A♢  7♠
A♡  7337♢  J♠  54943♠  J♣  696♠  T♢  3♡  A♠  8♡  K♡  24♠  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

About

A package for representing playing cards for card games.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages