bet retries on invalid input
This commit is contained in:
parent
0a72da768e
commit
10d00c8ef5
2 changed files with 25 additions and 2 deletions
12
src/game.rs
12
src/game.rs
|
|
@ -29,6 +29,7 @@ pub struct EndState {
|
|||
pub player_winnings: u64,
|
||||
pub dealer_cards: Vec<Card>,
|
||||
pub player_cards: Vec<Card>,
|
||||
pub shuffled: bool,
|
||||
}
|
||||
|
||||
impl EndState {
|
||||
|
|
@ -37,12 +38,14 @@ impl EndState {
|
|||
player_winnings: u64,
|
||||
dealer_cards: Vec<Card>,
|
||||
player_cards: Vec<Card>,
|
||||
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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue