From 48327efe20ebde69e688b2739fe6aac392fafaf4 Mon Sep 17 00:00:00 2001 From: Nick Pegg Date: Wed, 9 Jul 2025 12:40:15 -0700 Subject: [PATCH] clippy pass --- src/game.rs | 5 +++-- src/hand.rs | 6 ++++++ src/main.rs | 11 ++++------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/game.rs b/src/game.rs index a86cc9b..958c67b 100644 --- a/src/game.rs +++ b/src/game.rs @@ -128,7 +128,7 @@ impl Table { } /// Reset the shoe - combine shoe and discard and shuffle - fn shuffle(self: &mut Self) { + fn shuffle(&mut self) { self.shoe.append(&mut self.discard); assert_eq!(self.discard.len(), 0); self.shoe.shuffle(&mut self.rng); @@ -155,7 +155,7 @@ impl Table { // Shuffle the deck if we've played over 75% of cards let discard_size = self.discard.len(); - if self.shoe.len() < (self.shoe.len() + discard_size) * 1 / 4 { + if self.shoe.len() < (self.shoe.len() + discard_size) / 4 { self.shuffle(); player.shuffled = true; } @@ -213,6 +213,7 @@ impl Table { player_hand: turn.hand.clone(), returns: 0, }; + #[allow(clippy::if_same_then_else)] if self.dealer_hand.is_blackjack() { end_state.result = PlayResult::DealerBlackjack; } else if turn.hand.is_blackjack() { diff --git a/src/hand.rs b/src/hand.rs index b0ae954..a9fb694 100644 --- a/src/hand.rs +++ b/src/hand.rs @@ -91,6 +91,12 @@ impl Hand { } } +impl Default for Hand { + fn default() -> Self { + Hand::new() + } +} + impl From> for Hand { fn from(cards: Vec) -> Self { Self { cards } diff --git a/src/main.rs b/src/main.rs index e4aa70e..63ce316 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,10 +34,7 @@ struct Args { fn interactive_play() -> anyhow::Result<()> { // TODO: Make a way to reset bank let term = Term::stdout(); - let mut bank: u32 = match load_bank()? { - Some(b) => b, - None => 1_000, - }; + let mut bank: u32 = load_bank()?.unwrap_or(1_000); let mut table = Table::new(6, bank).with_hit_on_soft_17(); let mut last_bet: Option = None; @@ -53,7 +50,7 @@ fn interactive_play() -> anyhow::Result<()> { print!("Your bet [{}]? ", last_bet); io::stdout().flush().unwrap(); let input = term.read_line()?; - if input == "" { + if input.is_empty() { bet = last_bet; } else { match input.parse() { @@ -121,7 +118,7 @@ fn interactive_play_turn( turn: &mut PlayerTurn, table: &mut Table, ) -> anyhow::Result> { - let mut initial_play = true && !turn.was_split; + let mut initial_play = !turn.was_split; let mut other_turn = None; let term = Term::stdout(); @@ -222,7 +219,7 @@ fn basic_strategy( // Got a pair, maybe should split // We check can_split right at the get-go, because if we can't we just follow the Hard // Total table. - let aces = hand.cards()[0].value == String::from("A"); + let aces = hand.cards()[0].value == "A"; match hand.value() { 12 if aces => PlayerChoice::Split, 20 => PlayerChoice::Stand,