Skip to content

Commit

Permalink
Merge #41
Browse files Browse the repository at this point in the history
41: Small performance improvements r=charleskawczynski a=charleskawczynski



Co-authored-by: Charles Kawczynski <kawczynski.charles@gmail.com>
  • Loading branch information
bors[bot] and charleskawczynski authored Jul 25, 2023
2 parents eeefde0 + ebba886 commit 628b503
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PokerHandEvaluator"
uuid = "18ed25b1-892a-4a3b-b8fc-1036dc9a6a89"
authors = ["Charles Kawczynski <kawczynski.charles@gmail.com>"]
version = "0.2.4"
version = "0.2.5"

[deps]
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
Expand Down
25 changes: 25 additions & 0 deletions perf/benchmark.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using PlayingCards
using PlayingCards: AbstractDeck
import Random
Random.seed!(1234)
import PokerHandEvaluator as PHE

struct DummyDeck <: AbstractDeck
cards::Vector{Card}
end
Base.pop!(deck::DummyDeck, n::Int) = ntuple(i->deck.cards[i], n)
Random.shuffle!(deck::DummyDeck) = Random.shuffle!(Random.default_rng(), deck)

function Random.shuffle!(rng::Random.AbstractRNG, deck::DummyDeck)
Random.shuffle!(rng, deck.cards)
return deck
end

function do_work!(deck)
fhe = PHE.FullHandEval(pop!(deck, 7))
shuffle!(deck)
end

deck = DummyDeck(full_deck())
using BenchmarkTools
@benchmark do_work!($deck)
50 changes: 26 additions & 24 deletions src/best_hand_rank_from_n_cards.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,34 @@ function min_hand_rank_compact(hand_rank_1, cards)
end

function best_hand_rank_from_7_cards_full(c)
cards=(c[1],c[2],c[3],c[4],c[5]) # first combination
@inbounds begin
cards=(c[1],c[2],c[3],c[4],c[5]) # first combination

hand_rank = evaluate5(cards)
hand_type = hand_type_binary_search(hand_rank)
hr = (hand_rank, hand_type, cards)
hand_rank = evaluate5(cards)
hand_type = hand_type_binary_search(hand_rank)
hr = (hand_rank, hand_type, cards)

cards=(c[1],c[2],c[3],c[4],c[6]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[2],c[3],c[4],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[2],c[3],c[5],c[6]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[2],c[3],c[5],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[2],c[3],c[6],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[2],c[4],c[5],c[6]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[2],c[4],c[5],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[2],c[4],c[6],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[2],c[5],c[6],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[3],c[4],c[5],c[6]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[3],c[4],c[5],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[3],c[4],c[6],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[3],c[5],c[6],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[4],c[5],c[6],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[2],c[3],c[4],c[5],c[6]); hr = min_hand_rank_full(hr, cards)
cards=(c[2],c[3],c[4],c[5],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[2],c[3],c[4],c[6],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[2],c[3],c[5],c[6],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[2],c[4],c[5],c[6],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[3],c[4],c[5],c[6],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[2],c[3],c[4],c[6]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[2],c[3],c[4],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[2],c[3],c[5],c[6]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[2],c[3],c[5],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[2],c[3],c[6],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[2],c[4],c[5],c[6]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[2],c[4],c[5],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[2],c[4],c[6],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[2],c[5],c[6],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[3],c[4],c[5],c[6]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[3],c[4],c[5],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[3],c[4],c[6],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[3],c[5],c[6],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[1],c[4],c[5],c[6],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[2],c[3],c[4],c[5],c[6]); hr = min_hand_rank_full(hr, cards)
cards=(c[2],c[3],c[4],c[5],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[2],c[3],c[4],c[6],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[2],c[3],c[5],c[6],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[2],c[4],c[5],c[6],c[7]); hr = min_hand_rank_full(hr, cards)
cards=(c[3],c[4],c[5],c[6],c[7]); hr = min_hand_rank_full(hr, cards)
end
return hr
end

Expand Down
10 changes: 6 additions & 4 deletions src/evaluate5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ evaluate5(cards::Card...)::Int = evaluate5(cards)
# based on flush/non-flush:
function evaluate5(t::NTuple{N,Card})::Int where {N}
@assert N == 5
if suit(t[1]) == suit(t[2]) == suit(t[3]) == suit(t[4]) == suit(t[5])
return hash_table_suited[prod(prime.(t))]
else
return hash_table_offsuit[prod(prime.(t))]
@inbounds begin
if suit(t[1]) == suit(t[2]) == suit(t[3]) == suit(t[4]) == suit(t[5])
return hash_table_suited[prod(prime, t)]
else
return hash_table_offsuit[prod(prime, t)]
end
end
end

Expand Down

2 comments on commit 628b503

@charleskawczynski
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/88260

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.5 -m "<description of version>" 628b503a9fc5da0e1d4325815e8b546fcbcc9cb1
git push origin v0.2.5

Please sign in to comment.