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