double down tweaks
This commit is contained in:
parent
498586344c
commit
83aa05a611
2 changed files with 26 additions and 9 deletions
|
|
@ -156,6 +156,11 @@ impl Game {
|
||||||
player_hand.push(self.deal());
|
player_hand.push(self.deal());
|
||||||
}
|
}
|
||||||
PlayerChoice::DoubleDown => {
|
PlayerChoice::DoubleDown => {
|
||||||
|
if player_hand.cards().len() >= 3 {
|
||||||
|
// Can only double-down as first move
|
||||||
|
// TODO: Provide feedback that this move is invalid
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if *money_on_table >= bet_amount {
|
if *money_on_table >= bet_amount {
|
||||||
*money_on_table -= bet_amount;
|
*money_on_table -= bet_amount;
|
||||||
bet_amount *= 2;
|
bet_amount *= 2;
|
||||||
|
|
|
||||||
30
src/main.rs
30
src/main.rs
|
|
@ -115,18 +115,27 @@ fn interactive_decision(hand: &Hand, dealer_showing: &Card) -> PlayerChoice {
|
||||||
|
|
||||||
fn basic_strategy(hand: &Hand, dealer_showing: &Card) -> PlayerChoice {
|
fn basic_strategy(hand: &Hand, dealer_showing: &Card) -> PlayerChoice {
|
||||||
// Source: https://en.wikipedia.org/wiki/Blackjack#Basic_strategy
|
// Source: https://en.wikipedia.org/wiki/Blackjack#Basic_strategy
|
||||||
// TODO: Add doubling when it's supported
|
|
||||||
let dv = u8::from(dealer_showing);
|
let dv = u8::from(dealer_showing);
|
||||||
|
let can_dd = hand.cards().len() == 2;
|
||||||
if hand.has_ace() && hand.cards().len() == 2 {
|
if hand.has_ace() && hand.cards().len() == 2 {
|
||||||
// Ace and some other card
|
// Ace and some other card
|
||||||
match hand.value() {
|
match hand.value() {
|
||||||
v if v >= 19 => PlayerChoice::Stand,
|
v if v >= 19 => PlayerChoice::Stand,
|
||||||
v if v == 18 && (7..=8).contains(&dv) => PlayerChoice::Stand,
|
v if v == 18 && (7..=8).contains(&dv) => PlayerChoice::Stand,
|
||||||
v if v == 18 && dv < 7 => PlayerChoice::DoubleDown,
|
v if v == 18 && dv < 7 && can_dd => PlayerChoice::DoubleDown,
|
||||||
v if v == 17 && (3..=6).contains(&dv) => PlayerChoice::DoubleDown,
|
v if v == 18 && dv < 7 => PlayerChoice::Stand,
|
||||||
v if (15..=16).contains(&v) && (4..=6).contains(&dv) => PlayerChoice::DoubleDown,
|
v if v == 17 && (3..=6).contains(&dv) && can_dd => PlayerChoice::DoubleDown,
|
||||||
v if (13..=14).contains(&v) && (5..=6).contains(&dv) => PlayerChoice::DoubleDown,
|
v if v == 17 && (3..=6).contains(&dv) => PlayerChoice::Hit,
|
||||||
v if v == 12 && dv == 6 => PlayerChoice::DoubleDown,
|
v if (15..=16).contains(&v) && (4..=6).contains(&dv) && can_dd => {
|
||||||
|
PlayerChoice::DoubleDown
|
||||||
|
}
|
||||||
|
v if (15..=16).contains(&v) && (4..=6).contains(&dv) => PlayerChoice::Hit,
|
||||||
|
v if (13..=14).contains(&v) && (5..=6).contains(&dv) && can_dd => {
|
||||||
|
PlayerChoice::DoubleDown
|
||||||
|
}
|
||||||
|
v if (13..=14).contains(&v) && (5..=6).contains(&dv) => PlayerChoice::Hit,
|
||||||
|
v if v == 12 && dv == 6 && can_dd => PlayerChoice::DoubleDown,
|
||||||
|
v if v == 12 && dv == 6 => PlayerChoice::Hit,
|
||||||
_ => PlayerChoice::Hit,
|
_ => PlayerChoice::Hit,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -134,9 +143,12 @@ fn basic_strategy(hand: &Hand, dealer_showing: &Card) -> PlayerChoice {
|
||||||
v if v >= 17 => PlayerChoice::Stand,
|
v if v >= 17 => PlayerChoice::Stand,
|
||||||
v if v > 12 && dv < 7 => PlayerChoice::Stand,
|
v if v > 12 && dv < 7 => PlayerChoice::Stand,
|
||||||
v if v == 12 && (4..=6).contains(&dv) => PlayerChoice::Stand,
|
v if v == 12 && (4..=6).contains(&dv) => PlayerChoice::Stand,
|
||||||
v if v == 11 => PlayerChoice::DoubleDown,
|
v if v == 11 && can_dd => PlayerChoice::DoubleDown,
|
||||||
v if v == 10 && dv < 10 => PlayerChoice::DoubleDown,
|
v if v == 11 => PlayerChoice::Hit,
|
||||||
v if v == 9 && (3..=6).contains(&dv) => PlayerChoice::DoubleDown,
|
v if v == 10 && dv < 10 && can_dd => PlayerChoice::DoubleDown,
|
||||||
|
v if v == 10 && dv < 10 => PlayerChoice::Hit,
|
||||||
|
v if v == 9 && (3..=6).contains(&dv) && can_dd => PlayerChoice::DoubleDown,
|
||||||
|
v if v == 9 && (3..=6).contains(&dv) => PlayerChoice::Hit,
|
||||||
_ => PlayerChoice::Hit,
|
_ => PlayerChoice::Hit,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue