double down
This commit is contained in:
parent
782b52ca6c
commit
4387e2cb14
@ -10,7 +10,7 @@ pub struct BlackjackGame {
|
||||
pub enum PlayResult {
|
||||
DealerBlackJack, // Dealer has a blackjack. Player does not
|
||||
PlayerBlackJack, // Player has a blackjack. Dealer does not
|
||||
PushBlackjack, // Player and dealer have a blockjack
|
||||
PushBlackjack, // Player and dealer have a blackjack
|
||||
Push, // Dealer has a Blackjack and so does the Player
|
||||
Bust, // Player bust
|
||||
DealerBust, // Dealer bust
|
||||
@ -24,6 +24,7 @@ pub enum PlayResult {
|
||||
pub enum PlayMoves {
|
||||
Hit,
|
||||
Stand,
|
||||
DoubleDown,
|
||||
Bet, // At the Start of the game
|
||||
}
|
||||
|
||||
@ -97,7 +98,16 @@ impl BlackjackGame {
|
||||
}
|
||||
std::cmp::Ordering::Less => PlayResult::Continue,
|
||||
};
|
||||
}
|
||||
},
|
||||
(GameState::PlayerTurn, PlayMoves::DoubleDown) => {
|
||||
if self.player_hand.count() > 2{
|
||||
return PlayResult::InvalidMove;
|
||||
}
|
||||
|
||||
self.player_hand.add_card(self.shoe.pop_card().unwrap());
|
||||
self.state = GameState::Over;
|
||||
return self.dealer_play();
|
||||
},
|
||||
(GameState::PlayerTurn, PlayMoves::Stand) => {
|
||||
self.state = GameState::Over;
|
||||
return self.dealer_play();
|
||||
|
@ -12,12 +12,16 @@ pub fn play() -> Result<(), Box<dyn std::error::Error>> {
|
||||
print_full_state(&game);
|
||||
println!("Dealer wins with blackjack!");
|
||||
}
|
||||
crate::blackjack::PlayResult::PlayerBlackJack => println!("Player has a blackjack!"),
|
||||
crate::blackjack::PlayResult::PlayerBlackJack => {
|
||||
print_full_state(&game);
|
||||
println!("Player has a blackjack!");
|
||||
},
|
||||
crate::blackjack::PlayResult::PushBlackjack => {
|
||||
print_full_state(&game);
|
||||
println!("Player and Dealer have a blackjack!");
|
||||
}
|
||||
crate::blackjack::PlayResult::DealerBust => {
|
||||
print_full_state(&game);
|
||||
println!("Dealer busts. Player wins!");
|
||||
}
|
||||
crate::blackjack::PlayResult::StandPlayerLose => {
|
||||
@ -36,7 +40,7 @@ pub fn play() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
crate::blackjack::PlayResult::Push => {
|
||||
print_full_state(&game);
|
||||
println!("Player and dealer have the same value");
|
||||
println!("Player and dealer have the same value. Push!");
|
||||
}
|
||||
crate::blackjack::PlayResult::Bust => {
|
||||
print_full_state(&game);
|
||||
@ -66,7 +70,7 @@ pub fn play() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
fn get_move() -> Result<PlayMoves, io::Error> {
|
||||
loop {
|
||||
println!("(H)it (S)tand");
|
||||
println!("(H)it (S)tand (D)double");
|
||||
let mut buffer = String::new();
|
||||
|
||||
stdin().read_line(&mut buffer)?;
|
||||
@ -74,6 +78,7 @@ fn get_move() -> Result<PlayMoves, io::Error> {
|
||||
match buffer.trim() {
|
||||
"h" | "H" => return Ok(PlayMoves::Hit),
|
||||
"s" | "S" => return Ok(PlayMoves::Stand),
|
||||
"d" | "D" => return Ok(PlayMoves::DoubleDown),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user