diff --git a/src/game.rs b/src/game.rs index 1f09fba..9316227 100644 --- a/src/game.rs +++ b/src/game.rs @@ -156,6 +156,11 @@ impl Game { player_hand.push(self.deal()); } 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 { *money_on_table -= bet_amount; bet_amount *= 2; diff --git a/src/main.rs b/src/main.rs index fb2b4c2..5a61da0 100644 --- a/src/main.rs +++ b/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 { // Source: https://en.wikipedia.org/wiki/Blackjack#Basic_strategy - // TODO: Add doubling when it's supported let dv = u8::from(dealer_showing); + let can_dd = hand.cards().len() == 2; if hand.has_ace() && hand.cards().len() == 2 { // Ace and some other card match hand.value() { v if v >= 19 => PlayerChoice::Stand, v if v == 18 && (7..=8).contains(&dv) => PlayerChoice::Stand, - v if v == 18 && dv < 7 => PlayerChoice::DoubleDown, - v if v == 17 && (3..=6).contains(&dv) => PlayerChoice::DoubleDown, - v if (15..=16).contains(&v) && (4..=6).contains(&dv) => PlayerChoice::DoubleDown, - v if (13..=14).contains(&v) && (5..=6).contains(&dv) => PlayerChoice::DoubleDown, - v if v == 12 && dv == 6 => PlayerChoice::DoubleDown, + v if v == 18 && dv < 7 && can_dd => PlayerChoice::DoubleDown, + v if v == 18 && dv < 7 => PlayerChoice::Stand, + v if v == 17 && (3..=6).contains(&dv) && can_dd => PlayerChoice::DoubleDown, + v if v == 17 && (3..=6).contains(&dv) => PlayerChoice::Hit, + 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, } } else { @@ -134,9 +143,12 @@ fn basic_strategy(hand: &Hand, dealer_showing: &Card) -> PlayerChoice { v if v >= 17 => PlayerChoice::Stand, v if v > 12 && dv < 7 => PlayerChoice::Stand, v if v == 12 && (4..=6).contains(&dv) => PlayerChoice::Stand, - v if v == 11 => PlayerChoice::DoubleDown, - v if v == 10 && dv < 10 => PlayerChoice::DoubleDown, - v if v == 9 && (3..=6).contains(&dv) => PlayerChoice::DoubleDown, + v if v == 11 && can_dd => PlayerChoice::DoubleDown, + v if v == 11 => PlayerChoice::Hit, + 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, } }