clippy pass
This commit is contained in:
parent
69a4239f90
commit
48327efe20
3 changed files with 13 additions and 9 deletions
|
|
@ -128,7 +128,7 @@ impl Table {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reset the shoe - combine shoe and discard and shuffle
|
/// Reset the shoe - combine shoe and discard and shuffle
|
||||||
fn shuffle(self: &mut Self) {
|
fn shuffle(&mut self) {
|
||||||
self.shoe.append(&mut self.discard);
|
self.shoe.append(&mut self.discard);
|
||||||
assert_eq!(self.discard.len(), 0);
|
assert_eq!(self.discard.len(), 0);
|
||||||
self.shoe.shuffle(&mut self.rng);
|
self.shoe.shuffle(&mut self.rng);
|
||||||
|
|
@ -155,7 +155,7 @@ impl Table {
|
||||||
|
|
||||||
// Shuffle the deck if we've played over 75% of cards
|
// Shuffle the deck if we've played over 75% of cards
|
||||||
let discard_size = self.discard.len();
|
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();
|
self.shuffle();
|
||||||
player.shuffled = true;
|
player.shuffled = true;
|
||||||
}
|
}
|
||||||
|
|
@ -213,6 +213,7 @@ impl Table {
|
||||||
player_hand: turn.hand.clone(),
|
player_hand: turn.hand.clone(),
|
||||||
returns: 0,
|
returns: 0,
|
||||||
};
|
};
|
||||||
|
#[allow(clippy::if_same_then_else)]
|
||||||
if self.dealer_hand.is_blackjack() {
|
if self.dealer_hand.is_blackjack() {
|
||||||
end_state.result = PlayResult::DealerBlackjack;
|
end_state.result = PlayResult::DealerBlackjack;
|
||||||
} else if turn.hand.is_blackjack() {
|
} else if turn.hand.is_blackjack() {
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,12 @@ impl Hand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Hand {
|
||||||
|
fn default() -> Self {
|
||||||
|
Hand::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<Vec<Card>> for Hand {
|
impl From<Vec<Card>> for Hand {
|
||||||
fn from(cards: Vec<Card>) -> Self {
|
fn from(cards: Vec<Card>) -> Self {
|
||||||
Self { cards }
|
Self { cards }
|
||||||
|
|
|
||||||
11
src/main.rs
11
src/main.rs
|
|
@ -34,10 +34,7 @@ struct Args {
|
||||||
fn interactive_play() -> anyhow::Result<()> {
|
fn interactive_play() -> anyhow::Result<()> {
|
||||||
// TODO: Make a way to reset bank
|
// TODO: Make a way to reset bank
|
||||||
let term = Term::stdout();
|
let term = Term::stdout();
|
||||||
let mut bank: u32 = match load_bank()? {
|
let mut bank: u32 = load_bank()?.unwrap_or(1_000);
|
||||||
Some(b) => b,
|
|
||||||
None => 1_000,
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut table = Table::new(6, bank).with_hit_on_soft_17();
|
let mut table = Table::new(6, bank).with_hit_on_soft_17();
|
||||||
let mut last_bet: Option<u32> = None;
|
let mut last_bet: Option<u32> = None;
|
||||||
|
|
@ -53,7 +50,7 @@ fn interactive_play() -> anyhow::Result<()> {
|
||||||
print!("Your bet [{}]? ", last_bet);
|
print!("Your bet [{}]? ", last_bet);
|
||||||
io::stdout().flush().unwrap();
|
io::stdout().flush().unwrap();
|
||||||
let input = term.read_line()?;
|
let input = term.read_line()?;
|
||||||
if input == "" {
|
if input.is_empty() {
|
||||||
bet = last_bet;
|
bet = last_bet;
|
||||||
} else {
|
} else {
|
||||||
match input.parse() {
|
match input.parse() {
|
||||||
|
|
@ -121,7 +118,7 @@ fn interactive_play_turn(
|
||||||
turn: &mut PlayerTurn,
|
turn: &mut PlayerTurn,
|
||||||
table: &mut Table,
|
table: &mut Table,
|
||||||
) -> anyhow::Result<Option<PlayerTurn>> {
|
) -> 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 mut other_turn = None;
|
||||||
|
|
||||||
let term = Term::stdout();
|
let term = Term::stdout();
|
||||||
|
|
@ -222,7 +219,7 @@ fn basic_strategy(
|
||||||
// Got a pair, maybe should split
|
// 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
|
// We check can_split right at the get-go, because if we can't we just follow the Hard
|
||||||
// Total table.
|
// Total table.
|
||||||
let aces = hand.cards()[0].value == String::from("A");
|
let aces = hand.cards()[0].value == "A";
|
||||||
match hand.value() {
|
match hand.value() {
|
||||||
12 if aces => PlayerChoice::Split,
|
12 if aces => PlayerChoice::Split,
|
||||||
20 => PlayerChoice::Stand,
|
20 => PlayerChoice::Stand,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue