aboutsummaryrefslogtreecommitdiff
path: root/internal/casino/cards.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/casino/cards.go')
-rw-r--r--internal/casino/cards.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/internal/casino/cards.go b/internal/casino/cards.go
index f263eb6..b1c2cbb 100644
--- a/internal/casino/cards.go
+++ b/internal/casino/cards.go
@@ -69,10 +69,24 @@ func (s *shoe) shuffle() {
}
func (s *shoe) draw() card {
- if s.shuffleAt > 0 && len(s.cards) <= int(float64(s.decks*52)*s.shuffleAt) {
+ if len(s.cards) == 0 {
+ // The shoe ran dry mid-round (only possible when the configured
+ // deck count is very small relative to the table): rebuild it
+ // rather than panic. The cut-card reshuffle itself happens
+ // between rounds via shuffleIfDue, never per draw.
s.shuffle()
}
card := s.cards[len(s.cards)-1]
s.cards = s.cards[:len(s.cards)-1]
return card
}
+
+// shuffleIfDue reshuffles the shoe once its remaining cards have fallen
+// to the shuffleAt fraction (the cut card). It must be called at round
+// boundaries only — shuffling between individual draws would let cards
+// already dealt to hands reappear from the new shoe.
+func (s *shoe) shuffleIfDue() {
+ if s.shuffleAt > 0 && len(s.cards) <= int(float64(s.decks*52)*s.shuffleAt) {
+ s.shuffle()
+ }
+}