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

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

View file

@ -99,13 +99,19 @@ fn interactive_decision(hand: &Hand, dealer_showing: &Card) -> PlayerChoice {
}
let choice: PlayerChoice;
let can_dd = hand.cards().len() == 2;
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();
choice = match read_input().to_lowercase().as_ref() {
"h" => PlayerChoice::Hit,
"s" => PlayerChoice::Stand,
"d" => PlayerChoice::DoubleDown,
"d" if can_dd => PlayerChoice::DoubleDown,
_ => continue,
};
break;
@ -215,7 +221,12 @@ fn save_bank(bank: u32) {
fn load_bank() -> Option<u32> {
let bank_path = data_dir().join("bank.txt");
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 {
None
}