auto-play dealer turn if not done by results() call; idiomatically handle split turns
This commit is contained in:
parent
b2115a4a7e
commit
2e31a68de3
2 changed files with 21 additions and 25 deletions
|
|
@ -211,6 +211,10 @@ impl Table {
|
|||
|
||||
/// Get the results
|
||||
pub fn results(&mut self, turn: PlayerTurn) -> Result<EndState, BlackjackError> {
|
||||
if self.phase == Phase::DealerTurn {
|
||||
self.dealers_turn()?;
|
||||
}
|
||||
|
||||
if self.phase != Phase::Results {
|
||||
return Err(BlackjackError::IncorrectAction(self.phase));
|
||||
}
|
||||
|
|
|
|||
38
src/main.rs
38
src/main.rs
|
|
@ -89,22 +89,20 @@ fn interactive_play(args: Args) -> anyhow::Result<()> {
|
|||
|
||||
let mut turn = table.deal_hand(bet);
|
||||
let split_turn = interactive_play_turn(&mut turn, &mut table, args.show_count)?;
|
||||
if split_turn.is_none() {
|
||||
table.dealers_turn()?;
|
||||
let result = table.results(turn)?;
|
||||
term.clear_screen()?;
|
||||
print_result(&result);
|
||||
} else {
|
||||
let mut split_turn = split_turn.unwrap();
|
||||
interactive_play_turn(&mut split_turn, &mut table, args.show_count)?;
|
||||
table.dealers_turn()?;
|
||||
let result = table.results(turn)?;
|
||||
let split_result = table.results(split_turn)?;
|
||||
let split_result = match split_turn {
|
||||
Some(mut st) => {
|
||||
interactive_play_turn(&mut st, &mut table, args.show_count)?;
|
||||
Some(table.results(st)?)
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
|
||||
term.clear_screen()?;
|
||||
let result = table.results(turn)?;
|
||||
print_result(&result);
|
||||
if let Some(r) = split_result {
|
||||
println!();
|
||||
print_result(&split_result);
|
||||
print_result(&r);
|
||||
}
|
||||
|
||||
table.end_game()?;
|
||||
|
|
@ -382,18 +380,12 @@ fn old_man(args: Args) -> anyhow::Result<()> {
|
|||
{
|
||||
let mut turn = table.deal_hand(MIN_BET);
|
||||
let split_turn = basic_strategy_play_turn(&mut turn, &mut table)?;
|
||||
if split_turn.is_none() {
|
||||
table.dealers_turn()?;
|
||||
table.results(turn)?;
|
||||
// No need to handle result since we take chips off table at end of day
|
||||
} else {
|
||||
let mut split_turn = split_turn.unwrap();
|
||||
basic_strategy_play_turn(&mut split_turn, &mut table)?;
|
||||
table.dealers_turn()?;
|
||||
// No need to handle result since we take chips off table at end of day
|
||||
table.results(turn)?;
|
||||
table.results(split_turn)?;
|
||||
if let Some(mut st) = split_turn {
|
||||
basic_strategy_play_turn(&mut st, &mut table)?;
|
||||
table.results(st)?;
|
||||
}
|
||||
table.results(turn)?;
|
||||
// No need to handle result since we take chips off table at end of day
|
||||
|
||||
table.end_game()?;
|
||||
rounds += 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue