Saturday, November 22, 2014

Meteor Addons


meteor add mizzao:bootstrap-3
meteor add underscore
meteor add mrt:moment
meteor add iron:router
meteor add sacha:spin
{{> spinner }}

meteor add ian:accounts-ui-bootstrap-3

meteor add accounts-password
{{> loginButtons }}

meteor add meteorhacks:npmhttps://meteorhacks.com/complete-npm-integration-for-meteor.html






meteor remove autopublish
Meteor.publish('posts', function() { return Posts.find();

});
Meteor.subscribe('posts');

meteor remove insecure

Wednesday, November 12, 2014

Monday, September 29, 2014

Blackjack Simulation Results - Player Stats

Background

If you look back at me previous two posts, you can see that I have been working on a Blackjack simulation in an attempt to beat the CSM. Funny, I know...

I apologize for the "ascii art" graphs. Right now, all my code is a quick and dirty simulation. I am planning to expose the code functionality with a GWT front-end with interactive, pretty D3 graphs. 

Basic Strategy

The following arrays were used as the basic strategy logic for the player.

private static final Character[][] HARD_BS = new Character[][] { {/* 0 */},{/* 1 */},{/* 2 */},{/* 3 */},{/* 4 */},
        //  2   3   4   5   6   7   8   9  10   A
        {  'H','H','H','H','H','H','H','H','H','H' }, // 5
        {  'H','H','H','H','H','H','H','H','H','H' }, // 6
        {  'H','H','H','H','H','H','H','H','H','H' }, // 7
        {  'H','H','H','H','H','H','H','H','H','H' }, // 8
        {  'H','D','D','D','D','H','H','H','H','H' }, // 9
        {  'D','D','D','D','D','D','D','D','H','H' }, // 10
        {  'D','D','D','D','D','D','D','D','D','H' }, // 11
        {  'S','S','S','S','S','H','H','H','H','H' }, // 12
        {  'S','S','S','S','S','H','H','H','H','H' }, // 13
        {  'S','S','S','S','S','H','H','H','H','H' }, // 14
        {  'S','S','S','S','S','H','H','H','r','H' }, // 15  r = RH
        {  'S','S','S','S','S','H','H','r','r','r' }, // 16  r = RH
        {  'S','S','S','S','S','S','S','S','S','S' }, // 17
        {  'S','S','S','S','S','S','S','S','S','S' }, // 18
        {  'S','S','S','S','S','S','S','S','S','S' }, // 19
        {  'S','S','S','S','S','S','S','S','S','S' }, // 20
        {  'S','S','S','S','S','S','S','S','S','S' }, // 21
    };
    
    private static final Character[][] SOFT_BS = new Character[][] { {/* 0 */}, {/* 1 */},
        //  2   3   4   5   6   7   8   9  10   A
        {  'H','H','H','D','D','H','H','H','H','H' }, // A,2
        {  'H','H','H','D','D','H','H','H','H','H' }, // A,3
        {  'H','H','D','D','D','H','H','H','H','H' }, // A,4
        {  'H','H','D','D','D','H','H','H','H','H' }, // A,5
        {  'H','D','D','D','D','H','H','H','H','H' }, // A,6
        {  'S','d','d','d','d','S','S','H','H','H' }, // A,7  d = DS
        {  'S','S','S','S','S','S','S','S','S','S' }, // A,8
        {  'S','S','S','S','S','S','S','S','S','S' }, // A,9
        {  'S','S','S','S','S','S','S','S','S','S' }, // A,10
    };
    
    private static final Character[][] DOUBLE_BS = new Character[][] { {/* 0 */}, {/* 1 */},
        //  2   3   4   5   6   7   8   9  10   A
        {  'P','P','P','P','P','P','H','H','H','H' }, // 2,2 
        {  'P','P','P','P','P','P','H','H','H','H' }, // 3,3
        {  'H','H','H','P','P','H','H','H','H','H' }, // 4,4
        {  'H','H','H','H','H','H','H','H','H','H' }, // 5,5
        {  'P','P','P','P','P','H','H','H','H','H' }, // 6,6
        {  'P','P','P','P','P','P','H','H','H','H' }, // 7,7
        {  'P','P','P','P','P','P','P','P','P','P' }, // 8,8
        {  'P','P','P','P','P','S','P','P','S','S' }, // 9,9
        {  'S','S','S','S','S','S','S','S','S','S' }, // 10,10
        {  'P','P','P','P','P','P','P','P','P','P' }, // A,A
    };

Player Stats

Here are the collected stats for a player using basic strategy over 10 million blackjack hands.

Hand Results Stats

Win Loss Ratio
 Win|****************************** 42.28%
Lose|*********************************** 49.59%
Push|****** 8.11%
===========================================================================
        10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Hard, Soft, Double Distribution
  HARD|***************************************************** 74.32%
  SOFT|********** 14.07%
DOUBLE|********* 11.60%
=============================================================================
          10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Hard Hand Distribution
      Win|************************** 37.13%
     Lose|*************************************** 55.61%
     Push|****** 7.25%
================================================================================
             10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Soft Hand Distribution
      Win|********************************************* 63.39%
     Lose|******************** 28.17%
     Push|****** 8.43%
================================================================================
             10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Double Hand Distribution
      Win|******************************************* 61.35%
     Lose|***************** 23.02%
     Push|*********** 15.61%
================================================================================
             10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Starting Card Stats

Starting Score Distribution
 4|* 0.30%
 5|* 1.25%
 6|** 1.52%
 7|** 2.43%
 8|*** 2.92%
 9|*** 3.66%
10|**** 4.32%
11|**** 4.97%
12|******* 9.24%
13|******* 9.78%
14|******* 8.72%
15|****** 8.38%
16|****** 7.25%
17|****** 7.34%
18|***** 6.50%
19|***** 6.12%
20|******** 10.42%
21|**** 4.78%
=========================================================================
      10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Chance of Winning For Each Starting Score
 4|******************* 26.63%
 5|*********************** 32.59%
 6|********************** 30.38%
 7|*********************** 31.75%
 8|************************** 36.09%
 9|****************************** 42.51%
10|*********************************** 49.62%
11|************************************** 53.62%
12|*********************** 32.18%
13|*********************** 32.62%
14|********************** 31.28%
15|****************** 25.29%
16|***************** 23.16%
17|********************** 30.62%
18|******************************* 42.98%
19|**************************************** 57.07%
20|************************************************** 70.21%
21|******************************************************************* 95.52%
=========================================================================
      10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Chance of Losing For Each Starting Score
 4|*********************************************** 65.93%
 5|******************************************** 62.85%
 6|********************************************** 64.48%
 7|******************************************* 60.21%
 8|*************************************** 55.46%
 9|********************************** 48.35%
10|***************************** 40.18%
11|**************************** 39.41%
12|********************************************* 63.07%
13|******************************************** 62.81%
14|********************************************* 64.24%
15|*************************************************** 72.08%
16|***************************************************** 74.96%
17|*************************************** 55.59%
18|******************************* 43.62%
19|********************* 29.56%
20|********* 12.02%
21| 0.0%
=========================================================================
      10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Note: The following graph has negative values that are represented as zero.

Player Edge For Each Starting Hand
 4| -39.29%
 5| -30.25%
 6| -34.10%
 7| -28.45%
 8| -19.36%
 9| -5.84%
10|******* 9.44%
11|********** 14.20%
12| -30.89%
13| -30.18%
14| -32.96%
15| -46.78%
16| -51.79%
17| -24.96%
18| -0.64%
19|******************** 27.51%
20|***************************************** 58.18%
21|******************************************************************* 95.52%
=========================================================================
      10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Busting Stats

The following is the chance of busting given that you have the specific total showing. Note that the rows do NOT sum to 1.

Chance of Busting For Each Starting Score
 4|************************ 33.90%
 5|**************** 21.48%
 6|******************* 25.90%
 7|********** 13.86%
 8|********* 12.65%
 9|********* 11.70%
10|****** 7.50%
11|* 1.08%
12|******************** 27.28%
13|******************* 27.10%
14|********************* 29.76%
15|************ 16.90%
16|******** 11.15%
17|** 2.01%
18|** 1.57%
19| 0.0%
20| 0.0%
21| 0.0%
=========================================================================
      10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|


Given all of the hands with totals exceeding 21, each row represents the probability that the busted hand had the corresponding starting value. Note that in the graph above, it is likely to bust when starting with double 2's. However, since the hand is very rare, you are unlikely to lose lot's of money while busting on double 2's.


Starting Score Bust Distribution
 4|* 0.82%
 5|** 2.15%
 6|*** 3.15%
 7|** 2.68%
 8|*** 2.95%
 9|*** 3.42%
10|** 2.59%
11|* 0.43%
12|*************** 20.12%
13|*************** 21.15%
14|*************** 20.72%
15|******** 11.31%
16|***** 6.45%
17|* 1.18%
18|* 0.81%
19| 0.0%
20| 0.0%
21| 0.0%
=========================================================================
      10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Last Score Before Bust Distribution
12|*********** 15.28%
13|************** 19.85%
14|***************** 24.07%
15|*************** 20.80%
16|************** 19.96%
=========================================================================
      10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Win Loss Ratios Based on Starting Card (annoying dump)

Starting With 4
      Win|******************* 26.63%
     Lose|*********************************************** 65.93%
     Push|****** 7.43%
Surrender| 0.0%
================================================================================
             10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Starting With 5
      Win|*********************** 32.59%
     Lose|******************************************** 62.85%
     Push|**** 4.54%
Surrender| 0.0%
================================================================================
             10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Starting With 6
      Win|********************** 30.38%
     Lose|********************************************** 64.48%
     Push|**** 5.12%
Surrender| 0.0%
================================================================================
             10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Starting With 7
      Win|*********************** 31.75%
     Lose|******************************************* 60.21%
     Push|****** 8.03%
Surrender| 0.0%
================================================================================
             10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Starting With 8
      Win|************************** 36.09%
     Lose|*************************************** 55.46%
     Push|****** 8.44%
Surrender| 0.0%
================================================================================
             10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Starting With 9
      Win|****************************** 42.51%
     Lose|********************************** 48.35%
     Push|******* 9.12%
Surrender| 0.0%
================================================================================
             10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Starting With 10
      Win|*********************************** 49.62%
     Lose|***************************** 40.18%
     Push|******** 10.19%
Surrender| 0.0%
================================================================================
             10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Starting With 11
      Win|************************************** 53.62%
     Lose|**************************** 39.41%
     Push|***** 6.95%
Surrender| 0.0%
================================================================================
             10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Starting With 12
      Win|*********************** 32.18%
     Lose|********************************************* 63.07%
     Push|**** 4.74%
Surrender| 0.0%
================================================================================
             10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Starting With 13
      Win|*********************** 32.62%
     Lose|******************************************** 62.81%
     Push|**** 4.55%
Surrender| 0.0%
================================================================================
             10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Starting With 14
      Win|********************** 31.28%
     Lose|********************************************* 64.24%
     Push|**** 4.47%
Surrender| 0.0%
================================================================================
             10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Starting With 15
      Win|****************** 25.29%
     Lose|********************************** 48.20%
     Push|** 2.61%
Surrender|***************** 23.88%
================================================================================
             10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Starting With 16
      Win|***************** 23.16%
     Lose|****************************** 41.91%
     Push|** 1.87%
Surrender|************************ 33.04%
================================================================================
             10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Starting With 17
      Win|********************** 30.62%
     Lose|*************************************** 55.59%
     Push|********** 13.77%
Surrender| 0.0%
================================================================================
             10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Starting With 18
      Win|******************************* 42.98%
     Lose|******************************* 43.62%
     Push|********** 13.39%
Surrender| 0.0%
================================================================================
             10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Starting With 19
      Win|**************************************** 57.07%
     Lose|********************* 29.56%
     Push|********** 13.35%
Surrender| 0.0%
================================================================================
             10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Starting With 20
      Win|************************************************** 70.21%
     Lose|********* 12.02%
     Push|************* 17.76%
Surrender| 0.0%
================================================================================
             10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Starting With 21
      Win|****************************************************************** 95.52%
     Lose| 0.0%
     Push|**** 4.47%
Surrender| 0.0%
================================================================================
             10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Next Steps

Since I am trying to beat CSM's (Continuous Shuffle Machines), card counting will not help me. The deck is shuffled after every hand so each card has equal probability of appearing in two consecutive hands. I will have to rely on different betting strategies and might have to alter basic strategy to take advantage of the betting strategies.

Blackjack Simulation Statistics - Dealer Stats

Background

Last post I mentioned that I am learning and studying blackjack in hopes of coming out on top during my next trip to a casino. And I have ... news. The casinos know what they are doing, and it is not looking so good. The following posts will detail the findings from my simulations. This article will concentrate on statistics about the dealer.

Code Coming Soon!

Also, I plan to make my Java code available on Github at some point in the future. It has configurable rules, implementable Player interface to allow AI bots and can simulate ~825,000 hands per second before any real attempt at optimization.

Dealer Stats


I wanted to confirm the distributions from Knock Out Blackjack. The following distributions presented themselves for the dealer over 1 million hands against a single player using basic strategy. To confirm a fair uniform shuffle I tracked the dealers starting card:

Dealer's Starting Card: 
 2|****** 7.69%
 3|****** 7.69%
 4|****** 7.70%
 5|****** 7.70%
 6|****** 7.70%
 7|****** 7.69%
 8|****** 7.67%
 9|****** 7.67%
10|********************** 30.74%
 A|****** 7.70%
=========================================================================
      10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|


The following are distributions close to the values presented in Knock Out Blackjack. For the following distributions, "No Play" means that the player busted and the dealer had a total score of < 17:

Dealer Hand Ending Amount: 
     17|********** 14.03%
     18|********** 13.44%
     19|********** 12.86%
     20|************* 17.41%
     21|********* 11.46%
   Bust|******************* 25.86%
No Play|**** 4.90%
==============================================================================
           10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|


Low Cards - Likely to Bust

Ending Amount When Dealer Starts With 2 Showing: 
     17|********** 14.01%
     18|********** 13.49%
     19|********** 12.97%
     20|********* 12.41%
     21|********* 11.83%
   Bust|************************* 35.26%
No Play| 0.0%
==============================================================================
           10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Ending Amount When Dealer Starts With 3 Showing: 
     17|********** 13.36%
     18|********** 12.98%
     19|********* 12.53%
     20|********* 12.05%
     21|********* 11.55%
   Bust|*************************** 37.50%
No Play| 0.0%
==============================================================================
           10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Ending Amount When Dealer Starts With 4 Showing: 
     17|********** 13.04%
     18|********* 12.54%
     19|********* 12.09%
     20|********* 11.64%
     21|******** 11.14%
   Bust|**************************** 39.52%
No Play| 0.0%
==============================================================================
           10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Ending Amount When Dealer Starts With 5 Showing: 
     17|********* 12.11%
     18|********* 12.29%
     19|********* 11.77%
     20|******** 11.19%
     21|******** 10.81%
   Bust|****************************** 41.79%
No Play| 0.0%
==============================================================================
           10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Ending Amount When Dealer Starts With 6 Showing: 
     17|************ 16.59%
     18|******** 10.59%
     19|******** 10.71%
     20|******** 10.19%
     21|******* 9.72%
   Bust|****************************** 42.17%
No Play| 0.0%
==============================================================================

           10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|


Safe Zone Cards

Ending Amount When Dealer Starts With 7 Showing
     17|************************** 35.74%
     18|********* 12.68%
     19|***** 6.41%
     20|***** 6.38%
     21|***** 5.99%
   Bust|*************** 21.30%
No Play|********* 11.47%
==============================================================================
           10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Ending Amount When Dealer Starts With 8 Showing
     17|********* 11.94%
     18|************************* 34.89%
     19|********* 11.88%
     20|**** 5.63%
     21|**** 5.59%
   Bust|************** 19.68%
No Play|******** 10.35%
==============================================================================
           10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Ending Amount When Dealer Starts With 9 Showing
     17|******** 11.21%
     18|******** 10.95%
     19|************************* 34.37%
     20|******** 11.16%
     21|**** 4.90%
   Bust|************* 18.42%
No Play|******* 8.96%
==============================================================================
           10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Ending Amount When Dealer Starts With 10 Showing
     17|******** 10.63%
     18|******** 10.59%
     19|******** 10.62%
     20|************************ 33.44%
     21|******** 10.62%
   Bust|************* 17.82%
No Play|***** 6.24%
==============================================================================
           10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

Ending Amount When Dealer Starts With Ace Showing
     17|********* 11.87%
     18|********* 11.95%
     19|********* 11.99%
     20|********* 12.02%
     21|************************* 34.94%
   Bust|******* 9.16%
No Play|****** 8.03%
==============================================================================
           10%|   20%|   30%|   40%|   50%|   60%|   70%|   80%|   90%|

My next post will contain details about users hands.

Friday, September 19, 2014

Am Attempt to Beat Blackjack CSMs

I recently had an opportunity to learn and play blackjack in a smaller casino. After studying basic strategy and looking at an odds calculator I found that even with optimal play the casino still has an edge over players. So how do people make money playing blackjack?

Playing with basic strategy, it is given that you will lose more than you win. The details of this claim are based on statistics and can be found in a number of places on the internet. Since you cannot win more games you need to bet more intelligently.

If you bet more when you are more likely to win and bet less when likely to lose then you will gain a small advantage against the house. Enter "card counting". Most methods provide approximately 1% edge to the player.

Counting techniques require a player to track cards throughout play. This usually consists of raising and lowering bets based on the ratio of high to low cards.

First the casinos attempted to spot and ban counters. Technological advances made this easier but another more effective technique is on the rise. Continuous Shuffling Machines (CSM).

These are being placed on tables with lower minimums in an attempt to stop counters and speed up play.

A series of upcoming posts will outline my attempt at finding a way to beat the CSM's at the small casino. Keep posted for more technical discussions.