add old man simulation
This commit is contained in:
parent
a2d1695203
commit
c114094285
1 changed files with 58 additions and 0 deletions
58
src/main.rs
58
src/main.rs
|
|
@ -5,7 +5,9 @@ use std::io;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
// TODO: CLI flags to choose how to play
|
||||||
interactive_play();
|
interactive_play();
|
||||||
|
// old_man();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interactive_play() {
|
fn interactive_play() {
|
||||||
|
|
@ -102,6 +104,62 @@ fn interactive_decision(hand: &Hand, dealer_showing: &Card) -> PlayerChoice {
|
||||||
choice
|
choice
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 dealer_val = u8::from(dealer_showing);
|
||||||
|
if hand.has_ace() {
|
||||||
|
match hand.value() {
|
||||||
|
v if v >= 19 => PlayerChoice::Stand,
|
||||||
|
v if v == 18 && dealer_val < 9 => PlayerChoice::Stand,
|
||||||
|
_ => PlayerChoice::Hit,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
match hand.value() {
|
||||||
|
v if v >= 17 => PlayerChoice::Stand,
|
||||||
|
v if v > 12 && dealer_val < 7 => PlayerChoice::Stand,
|
||||||
|
v if v == 12 && (4..=6).contains(&dealer_val) => PlayerChoice::Stand,
|
||||||
|
_ => PlayerChoice::Hit,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An cab driver to the LAS airport was a former dealer and told me about this retired guy who
|
||||||
|
/// would come play Blackjack every day at 7am like clockwork. He'd bring $400 to the table, play
|
||||||
|
/// basic strategy, and would walk away once he was $100 up. He made about $3000/mo off of this, in
|
||||||
|
/// addition to points/comps which he would use to eat brunch for free.
|
||||||
|
///
|
||||||
|
/// Does this actually work, or was the driver full of it?
|
||||||
|
fn old_man() {
|
||||||
|
let mut bank: u64 = 100_000;
|
||||||
|
const PER_DAY: u32 = 400;
|
||||||
|
const MIN_BET: u32 = 15;
|
||||||
|
// Walk away when we're up by this much
|
||||||
|
const WALK_AWAY: u32 = 100;
|
||||||
|
const DAYS: u8 = 30;
|
||||||
|
|
||||||
|
println!("Starting with bank: ${bank}");
|
||||||
|
// Let's simulate this for 30 days
|
||||||
|
for day in 1..=DAYS {
|
||||||
|
let mut in_hand: u32 = PER_DAY;
|
||||||
|
bank -= in_hand as u64;
|
||||||
|
|
||||||
|
let mut game = Game::new().with_decks(6);
|
||||||
|
let mut rounds = 0;
|
||||||
|
while in_hand > MIN_BET && in_hand < (PER_DAY + WALK_AWAY) {
|
||||||
|
let bet = MIN_BET;
|
||||||
|
in_hand -= bet;
|
||||||
|
let result = game.play(bet, basic_strategy);
|
||||||
|
in_hand += u32::try_from(result.player_winnings).unwrap();
|
||||||
|
rounds += 1;
|
||||||
|
}
|
||||||
|
println!("Day {day}, after {rounds} rounds, in-hand: ${in_hand}");
|
||||||
|
bank += in_hand as u64;
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Ending with: ${bank}");
|
||||||
|
}
|
||||||
|
|
||||||
fn read_input() -> String {
|
fn read_input() -> String {
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
io::stdin().read_line(&mut buf).unwrap();
|
io::stdin().read_line(&mut buf).unwrap();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue