Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deck #6

Merged
merged 1 commit into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/NoLimitHoldem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ using Random

include("card.jl")
include("hand.jl")
include("deck.jl")

end # module
27 changes: 27 additions & 0 deletions src/deck.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#### Deck

export Deck,
shuffle!,
OrderedDeck

struct Deck{C <: Vector}
cards::C
end

Base.length(deck::Deck) = length(deck.cards)
Base.pop!(deck::Deck, n::Integer) = ntuple(i->pop!(deck.cards), n)

function OrderedDeck()
deck = Card[]
for r in rank_list
for s in suit_list
push!(deck, Card(r,s))
end
end
return Deck(deck)
end

function shuffle!(deck::Deck)
deck.cards .= deck.cards[randperm(length(deck.cards))]
nothing
end
15 changes: 15 additions & 0 deletions test/Deck.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Test
using NoLimitHoldem
using NoLimitHoldem: suit_list, rank_list
const NLH = NoLimitHoldem

@testset "Deck" begin

deck = OrderedDeck()
@test length(deck) == 52
shuffle!(deck)

cards = pop!(deck, 2)
@test length(deck) == 50
@test length(cards) == 2
end
3 changes: 1 addition & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using Test

for submodule in [
"Card",
"Hand",
"Deck",
]

println("Starting tests for $submodule")
Expand Down