flag to show card count

This commit is contained in:
Nick Pegg 2025-07-09 18:07:11 -07:00
parent 48327efe20
commit 1106f1484f
2 changed files with 27 additions and 9 deletions

View file

@ -127,6 +127,14 @@ impl Table {
self.player_chips
}
pub fn count(&self) -> i16 {
self.count
}
pub fn shoe_count(&self) -> usize {
self.shoe.len()
}
/// Reset the shoe - combine shoe and discard and shuffle
fn shuffle(&mut self) {
self.shoe.append(&mut self.discard);

View file

@ -13,7 +13,7 @@ fn main() -> anyhow::Result<()> {
// TODO: Use anyhow for error handling, get rid of unwraps
let args = Args::parse();
match args.mode {
Mode::Interactive => interactive_play(),
Mode::Interactive => interactive_play(args.show_count),
Mode::OldMan => old_man(),
}
}
@ -29,9 +29,12 @@ enum Mode {
struct Args {
#[arg(long, default_value = "interactive")]
mode: Mode,
#[arg(long, default_value_t = false)]
show_count: bool,
}
fn interactive_play() -> anyhow::Result<()> {
fn interactive_play(show_count: bool) -> anyhow::Result<()> {
// TODO: Make a way to reset bank
let term = Term::stdout();
let mut bank: u32 = load_bank()?.unwrap_or(1_000);
@ -40,7 +43,11 @@ fn interactive_play() -> anyhow::Result<()> {
let mut last_bet: Option<u32> = None;
loop {
println!("\nMoney in the bank: {bank}");
println!("\nMoney in the bank: ${bank}");
if show_count {
println!("Card count: {}", table.count());
println!("Cards in shoe: {}", table.shoe_count());
}
// Bet checking loop
let mut bet: u32;
@ -77,11 +84,7 @@ fn interactive_play() -> anyhow::Result<()> {
println!();
let mut turn = table.deal_hand(bet);
if turn.shuffled {
println!("Deck was shuffled");
}
let split_turn = interactive_play_turn(&mut turn, &mut table)?;
let split_turn = interactive_play_turn(&mut turn, &mut table, show_count)?;
if split_turn.is_none() {
table.dealers_turn()?;
let result = table.results(turn)?;
@ -89,7 +92,7 @@ fn interactive_play() -> anyhow::Result<()> {
print_result(&result);
} else {
let mut split_turn = split_turn.unwrap();
interactive_play_turn(&mut split_turn, &mut table)?;
interactive_play_turn(&mut split_turn, &mut table, show_count)?;
table.dealers_turn()?;
let result = table.results(turn)?;
let split_result = table.results(split_turn)?;
@ -117,6 +120,7 @@ fn interactive_play() -> anyhow::Result<()> {
fn interactive_play_turn(
turn: &mut PlayerTurn,
table: &mut Table,
show_count: bool,
) -> anyhow::Result<Option<PlayerTurn>> {
let mut initial_play = !turn.was_split;
let mut other_turn = None;
@ -126,6 +130,12 @@ fn interactive_play_turn(
term.clear_screen()?;
let hand = turn.player_hand();
if turn.shuffled {
println!("Deck was shuffled");
}
if show_count {
println!("Card count: {}", table.count());
}
println!("Your bet: ${}", turn.bet);
println!("Dealer showing: {}", table.dealer_showing());
println!("Your hand: {hand}");