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
|
/// Get the results
|
||||||
pub fn results(&mut self, turn: PlayerTurn) -> Result<EndState, BlackjackError> {
|
pub fn results(&mut self, turn: PlayerTurn) -> Result<EndState, BlackjackError> {
|
||||||
|
if self.phase == Phase::DealerTurn {
|
||||||
|
self.dealers_turn()?;
|
||||||
|
}
|
||||||
|
|
||||||
if self.phase != Phase::Results {
|
if self.phase != Phase::Results {
|
||||||
return Err(BlackjackError::IncorrectAction(self.phase));
|
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 mut turn = table.deal_hand(bet);
|
||||||
let split_turn = interactive_play_turn(&mut turn, &mut table, args.show_count)?;
|
let split_turn = interactive_play_turn(&mut turn, &mut table, args.show_count)?;
|
||||||
if split_turn.is_none() {
|
let split_result = match split_turn {
|
||||||
table.dealers_turn()?;
|
Some(mut st) => {
|
||||||
let result = table.results(turn)?;
|
interactive_play_turn(&mut st, &mut table, args.show_count)?;
|
||||||
term.clear_screen()?;
|
Some(table.results(st)?)
|
||||||
print_result(&result);
|
}
|
||||||
} else {
|
None => None,
|
||||||
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)?;
|
|
||||||
|
|
||||||
term.clear_screen()?;
|
term.clear_screen()?;
|
||||||
|
let result = table.results(turn)?;
|
||||||
print_result(&result);
|
print_result(&result);
|
||||||
|
if let Some(r) = split_result {
|
||||||
println!();
|
println!();
|
||||||
print_result(&split_result);
|
print_result(&r);
|
||||||
}
|
}
|
||||||
|
|
||||||
table.end_game()?;
|
table.end_game()?;
|
||||||
|
|
@ -382,18 +380,12 @@ fn old_man(args: Args) -> anyhow::Result<()> {
|
||||||
{
|
{
|
||||||
let mut turn = table.deal_hand(MIN_BET);
|
let mut turn = table.deal_hand(MIN_BET);
|
||||||
let split_turn = basic_strategy_play_turn(&mut turn, &mut table)?;
|
let split_turn = basic_strategy_play_turn(&mut turn, &mut table)?;
|
||||||
if split_turn.is_none() {
|
if let Some(mut st) = split_turn {
|
||||||
table.dealers_turn()?;
|
basic_strategy_play_turn(&mut st, &mut table)?;
|
||||||
table.results(turn)?;
|
table.results(st)?;
|
||||||
// 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)?;
|
|
||||||
}
|
}
|
||||||
|
table.results(turn)?;
|
||||||
|
// No need to handle result since we take chips off table at end of day
|
||||||
|
|
||||||
table.end_game()?;
|
table.end_game()?;
|
||||||
rounds += 1;
|
rounds += 1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue