aboutsummaryrefslogtreecommitdiff
path: root/internal/casino/blackjack_wagers.go
blob: 23afac8db5048e75948a0f82023a1f0498a7bb53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package casino

import "fmt"

// Blackjack's only standing wager is bet <amount>, so outside the hand's
// decision points its wager list is empty (which also suppresses the "list"
// hint). During the insurance window and the player's own turn, the extra
// wagers and wagers-that-return-money get listed: insurance, decline,
// double, split and surrender — the same facts their own hints carry.
func (t *blackjackTable) wagerRows(name string) []WagerRow {
	p := t.players.get(name)
	if p == nil {
		return nil
	}
	if t.phase == blackjackInsurance && p.HasBet && !p.declinedInsurance && p.insurance == 0 && len(p.hands) > 0 {
		return []WagerRow{
			{"insurance", fmt.Sprintf("%g:1", t.Rules.InsurancePayout), fmt.Sprintf("Covers dealer blackjack; the stake costs %d", p.hands[0].bet/2)},
			{"decline", "", "Continue without insurance (also the timeout default)"},
		}
	}
	if t.phase == blackjackPlaying && t.activeName() == name && t.activeHand < len(p.hands) {
		hand := p.hands[t.activeHand]
		var rows []WagerRow
		for _, action := range t.availableActions(p, hand) {
			switch action {
			case "hit":
				rows = append(rows, WagerRow{"hit", "", "Take another card"})
			case "stand":
				rows = append(rows, WagerRow{"stand", "", "Keep your total"})
			case "double":
				rows = append(rows, WagerRow{"double", "1:1 on the added stake", fmt.Sprintf("Wager %d more, take exactly one card, stand", hand.bet)})
			case "split":
				rows = append(rows, WagerRow{"split", "1:1 on the added stake", fmt.Sprintf("Wager %d more; play the pair as two hands", hand.bet)})
			case "surrender":
				rows = append(rows, WagerRow{"surrender", "half returned", "Give up the original two-card hand"})
			}
		}
		return rows
	}
	return nil
}