blackjack-simulator

command module
v0.0.0-...-eb5e1dc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

README

BlackJack Simulator

This is a Golang project designed to test BlackJack strategies.

4 strategies are already implemented:

  1. never-explode: never split and double, only hit on hard point < 12
  2. dealer: mimic dealer, always hit on point < 17
  3. basic: the basic strategy introduced in the book Beat the Dealer: A Winning Strategy for the Game of Twenty-One by Edward Thorp.
  4. ask-user: you can also play with the simulator by answering Y or N in command line

How to build:

go build -o blackjack-simulator.exe

How to check flags:

./blackjack-simulator.exe -h

How to run 10000 rounds of simulation using the basic strategy:

./blackjack-simulator.exe -r 10000 -s basic

Example output of running 10 rounds of simulation using the basic strategy:

$ .\blackjack-simulator.exe -r 10 -s basic
round 1 lose: [5 9 9] (23) V.S. [Q 6 9] (25) (player balance 0.0 - 1.0 => -1.0)       
round 2 lose: [9 J] (19) V.S. [9 3 9] (21) (player balance -1.0 - 1.0 => -2.0)        
round 3 lose: [4 5 4 K] (23) V.S. [K 10] (20) (player balance -2.0 - 1.0 => -3.0)     
round 4 lose: [7 3 2 2 10] (24) V.S. [K 8] (18) (player balance -3.0 - 1.0 => -4.0)   
round 5 win: [8 J] (18) V.S. [4 6 7] (17) (player balance -4.0 + 1.0 => -3.0)         
round 6 push: [7 2 J] (19) V.S. [8 A] (19) (player balance -3.0 unchanged)            
round 7 win: [10 Q] (20) V.S. [2 2 2 Q A] (17) (player balance -3.0 + 1.0 => -2.0)    
round 8 win: [A 5 8 A 6] (21) V.S. [7 Q] (17) (player balance -2.0 + 1.0 => -1.0)     
round 9 blackjack: [A Q] (21) V.S. [J Q] (20) (player balance -1.0 + 1.5 => 0.5)      
round 10 double win: [2 9 10] (21) V.S. [J 4 Q] (24) (player balance 0.5 + 2.0 => 2.5)
-----statistics-----
10 rounds, 10 hands, 5 win, 1 push, 4 lose
BlackJack analysis: 1 blackjacks (10.00%), 1 win, 0 push, margin 1.5, edge 150.00%, contribution 15.00%
Hit stand analysis: 8 hit/stand hands (80%), 3 win, 1 push, 4 lose, 37.50% win rate, margin -1, edge -12.50%, contribution -10.00%
Hit/Stand/BlackJack analysis: 9 hit/stand/blackjack hands (90%), 4 win, 1 push, 4 lose, 44.44% win rate, margin 0.5, edge 5.56%, contribition 5.00%
Double hand analysis: 1 doubles hands (10.00%), 1 win, 0 push, 0 lose, 100.00% win rate, margin 2, edge 200.00%, contribution 20.00%
Split analysis: 0 hands could split (0.00%), 0 splits (NaN%), 0 win, 0 push, 0 lose, NaN% win rate, margin 0, edge NaN%, contribution 0.00%
player edge = 25.000%

Example of playing the simulator:

$ .\blackjack-simulator.exe -r 10 -s ask-user
[K 8] (18) V.S. [10 ?], wanna double? N
[K 8] (18) V.S. [10 ?], wanna hit? N
round 1 push: [K 8] (18) V.S. [10 8] (18) (player balance 0.0 unchanged)
[K K] V.S. [3 ?], wanna split? Y
[K A] (21) V.S. [3 ?], wanna double? N
[K A] (21) V.S. [3 ?], wanna hit? N
[K J] (20) V.S. [3 ?], wanna double? N
[K J] (20) V.S. [3 ?], wanna hit? N
round 2 win push: [K A] (21) [K J] (20) V.S. [3 7 Q] (20) (player balance 0.0 + 1.0 => 2.0)
[K 9] (19) V.S. [Q ?], wanna double? N
[K 9] (19) V.S. [Q ?], wanna hit? N
round 3 win: [K 9] (19) V.S. [Q 8] (18) (player balance 2.0 + 1.0 => 3.0)

How to add new strategies:

  1. Implement the Strategy interface defined in this repo.
  2. Update the StrategyMap defined in the main.go
  3. Then run this program to see the result (set -s flag to the name of your strategy).

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL