more double-down fixes

This commit is contained in:
Nick Pegg 2025-07-05 16:45:51 -07:00
parent 83aa05a611
commit 5b62addaaa
2 changed files with 23 additions and 9 deletions

View file

@ -173,14 +173,17 @@ impl Game {
// if player busts, immediately lose bet // if player busts, immediately lose bet
if player_hand.value() > 21 { if player_hand.value() > 21 {
return EndState::new( break;
PlayResult::Bust,
dealer_hand.cards(),
player_hand.cards(),
shuffled,
);
} }
} }
if player_hand.value() > 21 {
return EndState::new(
PlayResult::Bust,
dealer_hand.cards(),
player_hand.cards(),
shuffled,
);
}
// Dealer turn // Dealer turn
while dealer_hand.value() < 17 { while dealer_hand.value() < 17 {

View file

@ -99,13 +99,19 @@ fn interactive_decision(hand: &Hand, dealer_showing: &Card) -> PlayerChoice {
} }
let choice: PlayerChoice; let choice: PlayerChoice;
let can_dd = hand.cards().len() == 2;
loop { loop {
print!("(h)it, (s)tand, (d)ouble-down? "); let mut msg = String::from("(h)it, (s)tand");
if can_dd {
msg += ", (d)ouble-down";
}
msg += "? ";
io::stdout().write_all(msg.as_bytes()).unwrap();
io::stdout().flush().unwrap(); io::stdout().flush().unwrap();
choice = match read_input().to_lowercase().as_ref() { choice = match read_input().to_lowercase().as_ref() {
"h" => PlayerChoice::Hit, "h" => PlayerChoice::Hit,
"s" => PlayerChoice::Stand, "s" => PlayerChoice::Stand,
"d" => PlayerChoice::DoubleDown, "d" if can_dd => PlayerChoice::DoubleDown,
_ => continue, _ => continue,
}; };
break; break;
@ -215,7 +221,12 @@ fn save_bank(bank: u32) {
fn load_bank() -> Option<u32> { fn load_bank() -> Option<u32> {
let bank_path = data_dir().join("bank.txt"); let bank_path = data_dir().join("bank.txt");
if fs::exists(&bank_path).unwrap() { if fs::exists(&bank_path).unwrap() {
Some(fs::read_to_string(&bank_path).unwrap().parse().unwrap()) let bank = fs::read_to_string(&bank_path).unwrap().parse().unwrap();
if bank > 0 {
Some(bank)
} else {
None
}
} else { } else {
None None
} }