Friday, February 11, 2022

Blackjack Using Dice (Dice Games Chapter 1)

I'm starting a new series called "Dice Games". In this series, I'll make up a bunch of dice games/experiments. Then I'll try to calculate what'll happen using probability. In the end Monte Carlo method will decide if I was correct or not. If you don't know what Monte Carlo method is, it's basically a computer simulating the experiments using random inputs many times. 

Let's start with the first game:

BLACKJACK USING DICE

The objective of this game is simple, get as close to 21 as you can but don't surpass it. You'll start with a random 2 dice roll, then you can hit (roll a die and add it to your score) or pass (keep your score). To make it simple, I will ignore the dealer aspect of this game for now. I'm just trying to find the best winning strategy. Where should you stop? Any guesses?

My Solution

Expected value is the average outcome if you were to roll a die a gazillion times. And it's defined as:  

Let $X$ be the finite list of all possible outcomes $\{x_1, x_2,...,x_n\}$ where all outcomes respectively have the probability $\{p_1, p_2,...,p_n\}$. Then the expected value is defined as 

\[E[X]=x_1 p_1 + x_2 p_2 + ... + x_n p_n\]

So for example let's calculate the expected value of a die. The list of all outcomes is $\{1,2,3,4,5,6\}$ with each of them having a probability of $\frac{1}{6}$. Then the expected value is 

\[E[\textrm{dice}]= 1 \times \frac{1}{6}+2 \times \frac{1}{6}+3 \times \frac{1}{6}+4 \times \frac{1}{6}+5 \times \frac{1}{6}+6 \times \frac{1}{6} = \frac{7}{2}=3.5 \]

This means that if you had infinite time to roll a die and to write the outcome  onto a paper, the average of your results be $3.5$. This makes sense right? So my winning strategy is: 

Hit if your score is less than $17.5$, pass otherwise.

 To see if this is a valid strategy I'll make my strategy play against these strategies:

1-Hit if your score is less than $15.5$, pass otherwise.

2-Hit if your score is less than $16.5$, pass otherwise.

3-Hit if your score is less than $18.5$, pass otherwise.

4-Hit if your score is less than $19.5$, pass otherwise.

5- Hit if your score is less than $20.5$, pass otherwise.

Let's Simulate it

The ones with the biggest score less than 21 gets +1 point. They all get the same dice rolls so I think it's a fair game. Here are the results over 100,000 games:



As you can see $17.5$ was indeed the correct strategy with $18.5$ coming close. I've also included their average winning scores and average overall scores for those who like looking at data:

Blue is the average winning score, red is the average score throughout the games.

 Also here are how many times each strategy has busted:



 So if we were to implement "blackjack using dice" game to a casino, we know what our strategy should be. But what if a dealer was involved? So you would win money if the dealer was bust but we wouldn't know what their first card was while hitting. Also, other player's scores wouldn't affect us.  In blackjack the dealer has 16.5 as their stopping point (so 17 and higher means stop). But this is not really realistic since it means that the dealer can almost never bust (only possibility is 16+6). So in order to make our game more like blackjack, where should the dealer stop?

I will explore these questions in the upcoming weeks when I have time.



Edit: Thanks to reddit user u/PrestigiousCoach4479 I saw a mistake that I've made. The fact that my strategy won while competing with those 5 strategies didn't mean that it would beat each strategy in 1v1. It wasn't transitive. As the user put it: "Your method for evaluating strategies is intransitive in general. You might have A beat B which beats C which beats A heads-up, and in a field of 4 strategies, D which loses to the first three heads-up might be first out of 4. Including a strategy that loses to the other strategies, and comes in last, might change which strategy wins." 

So let's test that. Thankfully my code was clean so it took only two minutes to configure it. Here are the results! 

Note: Since 17.5's and 18.5's scores were very close, I made them play 50000000 games instead of 100000 games. They were still very close!


Alas 17.5 still won...

No comments:

Post a Comment

Game Idea: Blobtopia

Blobtopia Project Announcement Blobtopia: A Journey in Coding Joy Lately, I’ve had a revelation: school and work h...