diff --git a/src/game.rs b/src/game.rs index 4d3721b..876f65b 100644 --- a/src/game.rs +++ b/src/game.rs @@ -29,6 +29,7 @@ pub struct EndState { pub player_winnings: u64, pub dealer_cards: Vec, pub player_cards: Vec, + pub shuffled: bool, } impl EndState { @@ -37,12 +38,14 @@ impl EndState { player_winnings: u64, dealer_cards: Vec, player_cards: Vec, + shuffled: bool, ) -> Self { Self { result, player_winnings, dealer_cards, player_cards, + shuffled, } } } @@ -107,8 +110,10 @@ impl Game { { // Shuffle the deck if we've played over 75% of cards let discard_size = self.discard.read().unwrap().len(); + let mut shuffled = false; if self.shoe.len() < (self.shoe.len() + discard_size) * 1 / 4 { self.shuffle(); + shuffled = true; } // Deal cards @@ -124,6 +129,7 @@ impl Game { 0, dealer_hand.cards(), player_hand.cards(), + shuffled, ); } else if player_hand.is_blackjack() { let returns = bet as f32 * self.blackjack_returns; @@ -132,6 +138,7 @@ impl Game { returns as u64, dealer_hand.cards(), player_hand.cards(), + shuffled, ); } @@ -153,6 +160,7 @@ impl Game { 0, dealer_hand.cards(), player_hand.cards(), + shuffled, ); } } @@ -168,6 +176,7 @@ impl Game { (bet * 2).into(), dealer_hand.cards(), player_hand.cards(), + shuffled, ) } else if dealer_hand.value() < player_hand.value() { EndState::new( @@ -175,6 +184,7 @@ impl Game { (bet * 2).into(), dealer_hand.cards(), player_hand.cards(), + shuffled, ) } else if dealer_hand.value() == player_hand.value() { EndState::new( @@ -182,6 +192,7 @@ impl Game { bet.into(), dealer_hand.cards(), player_hand.cards(), + shuffled, ) } else { EndState::new( @@ -189,6 +200,7 @@ impl Game { 0, dealer_hand.cards(), player_hand.cards(), + shuffled, ) } } diff --git a/src/main.rs b/src/main.rs index 1e00aa0..15649f4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,8 @@ fn main() { } fn interactive_play() { + // TODO: Persist bank between plays + // TODO: Make a way to reset bank let mut bank: u64 = 1_000; let mut game = Game::new().with_decks(6); let mut last_bet: Option = None; @@ -26,12 +28,18 @@ fn interactive_play() { if input == "" { bet = last_bet.unwrap(); } else { - bet = input.parse().unwrap(); + match input.parse() { + Ok(b) => bet = b, + Err(_) => continue, + } } } else { print!("Your bet? "); io::stdout().flush().unwrap(); - bet = read_input().parse().unwrap(); + match read_input().parse() { + Ok(b) => bet = b, + Err(_) => continue, + } } if bet as u64 <= bank { break; @@ -58,6 +66,9 @@ fn interactive_play() { PlayResult::DealerBlackjack => println!("Dealer got blackjack"), PlayResult::Bust => println!("You busted"), } + if result.shuffled { + println!("Deck was shuffled at beginning of round"); + } bank += result.player_winnings; }