PokerHandEvaluator.jl
Docs Build | |
Documentation | |
GHA CI | |
Code Coverage | |
Bors enabled |
A package for evaluating poker hands.
Installation
julia>]
(v1.x) pkg> add PokerHandEvaluator
Functionality
PokerHandEvaluator.jl can be used to determine which player wins in a game of poker. PokerHandEvaluator.jl exports two types:
CompactHandEval
: a compact hand evaluation with limited properties and getter-methods defined:hand_rank
hand_type
FullHandEval
: a comprehensive hand evaluation with more properties and additional methods defined:hand_rank
hand_type
best_cards
all_cards
Example
using PlayingCards, PokerHandEvaluator
table_cards = (J♡,J♣,2♣,3♢,5♣)
player_cards = (
(A♠,2♠,table_cards...),
(J♠,T♣,table_cards...),
);
fhe = FullHandEval.(player_cards);
winner_id = argmin(hand_rank.(fhe)) # = 2
winning_hand = hand_type(fhe[winner_id]) # = Trips()
winning_rank = hand_rank(fhe[winner_id]) # = 1842
winning_cards = best_cards(fhe[winner_id]) # = (J♠, T♣, J♡, J♣, 5♣)
allcards = all_cards(fhe[winner_id]) # = (J♠, T♣, J♡, J♣, 2♣, 3♢, 5♣)
Performance
julia> using PokerHandEvaluator
julia> phe_dir = dirname(dirname(pathof(PokerHandEvaluator)));
julia> include(joinpath(phe_dir, "perf.jl")) # compile first
Δt_per_hand_eval = 1.4598465e-5
julia> include(joinpath(phe_dir, "perf.jl"))
Δt_per_hand_eval = 1.082814e-6