Saturday, May 9, 2009

One of the features that I'm planning for my card counting site BarracudaFix is a way for users to pick a card counting system and learn it. I want the software to provide indicators of what the running count is and how the user should be altering their bets to maximize their advantage. I'm thinking that initially the end user should be able to browse several systems and pick one that provides a statistical advantage but has only a few rules to learn. Later as they become stronger players they can move up to a more sophisticated system.
This leads naturally to the concept of back testing. The idea for back testing is that I program the system to play blackjack using different fixed strategies. Then I record the results in a database table and average it over a few thousand runs. Then for each strategy I can present a graph to give the users an idea of how they can expect to fare.

Some of the strategies that I'm thinking about starting out with are:
  • Playing using the dealer's fixed rules
  • Random hit, stand, double & split (when allowed)
  • Correct Basic Strategy
  • Several 10 count card counting strategies that work by altering the bets
  • Adaptive basic strategies that change the basic strategy
  • Strategies that involve combining the 10 count betting and the adaptive basic strategies
  • A 'perfect' strategy where the betting is optimal and each play is optimal based on the cards seen so far
  • Strategies that are as close to perfect as the player is able to obtain but also include moves that are designed to avert suspicion. Splitting 10s is a good example of such a move. Normally you should never split 10s but in certain circumstances it can be a 'cheap' way to make the casino management think you are just lucky etc.

I coded a system to sit in an infinite loop and at each pass:
  • calculate a bet
  • be dealt a hand
  • look up the correct play
  • play the hand out and let the dealer play
  • print out the current bankroll
I was really expecting to see the dollar amount fluctuate but eventually rise higher and higher. I wanted to let this code run for several hours, come back and see how well the player had done. Instead I saw it lock up after only a few seconds each time. To me it looked like a classic deadlock but there was one problem - I wasn't using multiple threads. This was all coded in a single tight while loop. I used tools like jconsole and jvisualvm to try and detect deadlocks or just provide a thread dump to show me where in my code I was hung.
There were no deadlocks detected but I did notice that my own code was consistently hung up either doing string concatenation or some operation on a list or set. I started recoding my app to use more primitive constructions so that it looked less and less like Java and more like C but it would only move the the spot where the code would hang to a new location in the source.
Anyway at this point I thought I was dealing with a bug in the jvm, I tried downgrading my version of java, I started to rewrite the entire system in php and ruby etc.
Anyway what finally helped out was to add a Thread.sleep(50) inside my loop. I still don't understand what exactly is going on when the hang up occurs but it appears to be a thread starvation situation.
So I'm back on task to add those simulations that I discuss above. Look for them in the coming weeks!

Saturday, April 11, 2009

setting up a card counting website

I'm starting this blog to talk about my website http://www.barracudafix.com
The idea behind this website is to create a web application that will allow a user to become a proficient card counter at casino blackjack.
I started playing blackjack a few years ago when I moved to Arizona and discovered the indian casinos in the area. One night after I lost some money I came home and decided to look online for a program to make me a better card player. I didn't like any of the programs that I found. They either seemed to be 10 to 15 year old shareware that was first released on Windows 3.1 or they were flash based games that were more advertisement than game.
The one thing that all these had in common was that they were trying to recreate the feeling of being in a casino. They would have green backgrounds and animated poker chips. Not only did I not think that these apps would help me improve my game I didn't want to spend any time at all with them.
My next stop was the library where I read about the history of card counting starting with Thorpe. This is more what I was looking for and had some good information . I was really impressed with the push to simplify the card counting systems to try and derive the most advantage with the least amount of mental effort on the part of the card counter.
The main problem I found with these books though was that the math seemed a little less than rigorous. Most of the books I read would talk about some computer simulations that were run on "super computers" back the late 70s or 80s and then present the results which you pretty much had to take on faith. There doesn't seem to be a single set of axioms that everyone agrees on. Part of this is that there are lots of variations in game itself. The bigger issue seems to be that all the authors approach the analysis from whatever background they had. I'll try and expand on this in further blog posts.
My next step was to go to source forge and see what other programs had been started in this space. I found a handful of blackjack programs written in C++ or python. None of these seemed like really polished apps. The ability to split hands up to four times is a pretty good litmus test. The apps I saw on source forge couldn't handle this from what I recall.
At that point I was ready to start coding. I worked on a blackjack engine that I played from a command line interface. Later I used the swing framework to build a simple gui which I later abandoned in favor of a pure webapp. My current technology is java 1.5, tomcat, spring, spring security, mysql, ajax, and dojo - developed on windows and deployed to Red Hat Linux server.
Currently I support playing a game of 21, creating a user account, seeing the correct basic strategy play for the hand you are playing. If you play while logged in the software will record all the mistakes you make. Once you have a few mistakes you can select to play a Training Game. In this game you will only be dealt situations that you have played incorrectly in the past.
I'm also indicating the deck penetration and the count for a particular system ... all in anticipation for rolling out card counting features.