clippy pass

This commit is contained in:
Nick Pegg 2025-07-09 12:40:15 -07:00
parent 69a4239f90
commit 48327efe20
3 changed files with 13 additions and 9 deletions

View file

@ -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() {

View file

@ -91,6 +91,12 @@ impl Hand {
}
}
impl Default for Hand {
fn default() -> Self {
Hand::new()
}
}
impl From<Vec<Card>> for Hand {
fn from(cards: Vec<Card>) -> Self {
Self { cards }

View file

@ -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<u32> = 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<Option<PlayerTurn>> {
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,