diff --git a/src/game.rs b/src/game.rs index 405f5d5..c7d1ab3 100644 --- a/src/game.rs +++ b/src/game.rs @@ -201,7 +201,9 @@ impl Table { return Err(BlackjackError::IncorrectAction(self.phase)); } - if turn.hand.value() <= 21 { + // TODO: Instead of checking pending results, we should probably check to see if there are + // any unbusted hands out. Might require us to hold on to turns locally. + if turn.hand.value() <= 21 || self.pending_results > 1 { while self.dealer_hand.value() < 17 { let dealer_card = self.deal_card(); self.dealer_hand.push(dealer_card); @@ -213,10 +215,6 @@ impl Table { /// Get the results pub fn results(&mut self, turn: PlayerTurn) -> Result { - if self.phase == Phase::DealerTurn { - self.dealers_turn(&turn)?; - } - if self.phase != Phase::Results { return Err(BlackjackError::IncorrectAction(self.phase)); } diff --git a/src/main.rs b/src/main.rs index 6820099..4fd7dfb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,21 +92,18 @@ fn interactive_play(args: Args) -> anyhow::Result<()> { println!(); let mut turn = table.deal_hand(bet); - let split_turn = interactive_play_turn(&mut turn, &mut table, &args)?; - let split_result = match split_turn { - Some(mut st) => { - interactive_play_turn(&mut st, &mut table, &args)?; - Some(table.results(st)?) - } - None => None, - }; + let mut split_turn = interactive_play_turn(&mut turn, &mut table, &args)?; + if let Some(st) = &mut split_turn { + interactive_play_turn(st, &mut table, &args)?; + } + table.dealers_turn(&turn)?; term.clear_screen()?; let result = table.results(turn)?; print_result(&result); - if let Some(r) = split_result { + if let Some(st) = split_turn { println!(); - print_result(&r); + print_result(&table.results(st)?); } table.end_game()?; @@ -387,9 +384,12 @@ fn old_man(args: Args) -> anyhow::Result<()> { && table.player_chips() > (PER_DAY - MAX_LOSS) { let mut turn = table.deal_hand(MIN_BET); - let split_turn = basic_strategy_play_turn(&mut turn, &mut table)?; - if let Some(mut st) = split_turn { - basic_strategy_play_turn(&mut st, &mut table)?; + let mut split_turn = basic_strategy_play_turn(&mut turn, &mut table)?; + if let Some(st) = &mut split_turn { + basic_strategy_play_turn(st, &mut table)?; + } + table.dealers_turn(&turn)?; + if let Some(st) = split_turn { table.results(st)?; } table.results(turn)?;