From 1106f1484ff4c5db39f5a7be10478ae0aef849dd Mon Sep 17 00:00:00 2001 From: Nick Pegg Date: Wed, 9 Jul 2025 18:07:11 -0700 Subject: [PATCH] flag to show card count --- src/game.rs | 8 ++++++++ src/main.rs | 28 +++++++++++++++++++--------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/game.rs b/src/game.rs index 958c67b..2007af2 100644 --- a/src/game.rs +++ b/src/game.rs @@ -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); diff --git a/src/main.rs b/src/main.rs index 63ce316..817c64e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 = 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> { 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}");