Introduction: Blackjack Basic Strategy Calculator
Blackjack is a card game where you and the dealer are both dealt 2 cards. You can see both of your cards but only one of the dealer's 2 cards. You then have up to 5 choices: stand, hit, split, double, or surrender.
For every particular combination of 3 visible cards one of the choices is statistically 'best'. Collectively these choices are called 'Basic Strategy' The basic strategy tables we will be using are given here
This instructables shows how to use an Arduino Uno and a few cheap components to build a calculator that gives you the basic strategy choice for any 3 cards entered (yours and the dealers 1). So lets get going...
Step 1: What You Need
This is what we need for the project:
- Arduino Uno (other Arduino can work but the code might need tweaking)
- 4x4 Universal 16 Key Switch Keypad (see picture)
- Keypad library for Arduino (download from here)
- One 10 pin 7-segment LED display any colour. See picture for the part number I used
- solder & soldering iron
- vero board
- Breadboard (optional)
- perspex for mounting about 5 inches by 8 inches (12cm X 20cm) - (optional)
- Printer with 1 sheet of adhesive printing paper
Step 2: Connecting the Hardware
It is a good idea to build this out on a breadboard first but it is not mandatory since I will explain how the 3 components (Arduino, keypad and 7 segment) are connected which is the main thing.
First connect the Arduino to the keypad. Assuming your keypad has the same (standard) mapping as mine then you need to connect it as in the diagram shown. What I did was solder an 8-pin header into the vero board and routed the plastic connector under the vero board and plugged it into the header. Then I took 8 wires chopped the pin of one end of each and stripped the insulation. then I soldered the chopped ends into the vero board by the header. The other end of each with the pin on is then plugged into the arduino. See the wiring diagram for details
Next I soldered the 7 segment display into the vero board. You need to break the tracks in between the two sets of 5 pins or solder it in across a bridge in the vero board. Next I did the same with 9 wires as for the keypad and soldered them in and plugged the pin ends into the arduino. Note that the middle pin in each set of 5 is common so only one needs to go to the Arduino 3.3v.
Step 3: About the Scripting
The keypad is controlled with the excellent Keypad Library for Arduino so you need to go here and download the library. The instructions are there too but basically you download the zip and put the zipped files in your "arduino\libraries\" folder wherever you installed the Arduino IDE.
For the rest of the sketch you can download mine that I have uploaded (basicStrat.ino) and load it onto the Arduino. I did some basic test but I take not responsibility for it so there could be bugs. One exercise you might want to do is go through the tables on the wiki page and test each one.
Take a look at the script too, I have tried to add comments in the significant parts and if you run it with the IDE there is also some diagnostic output printed to the serial monitor (from the IDE Tools > Serial Monitor or Ctrl + Shift + M).
Step 4: Finishing Touches
As mentioned in the parts section I mounted the vero board (with bolts), keypad (with adhesive on the back), and Arduino (again bots) onto perspex board. since the numbers and characters on the keypad are not exactly what we need I printed an overlay onto adhesive paper and stuck that over the keypad. The two black keys are not needed and there are 2 keys that can be used for an ace.
Also when the calculator is trying to tell you what to play it uses some codes. I also printed those codes onto sticky paper and stuck that on my perspex mount too. Download the image in this section and print it for both the keypad overlay and the codes.
Step 5: Testing
If you plug power into the USB port now it should work.
As you plug in only lights on the Arduino will light up, nothing on the 7 segment. To use it the sequence of steps is:
- key in the two cards you have in any order, display shows the cards
- key in the dealers card that is known
- the 7 segment display shows the code of the play to make. See the printed help card to interpret it
- repeat from 1 for the next hand
So as an example power up can hit 8, 3, K, if working correctly the display should show 'd.' (a d with a dot). This is telling us that we should double if allowed or hit i we can't. Now hit 8, 8 6 the display shows should show the symbol for split (l l) - you always split 8's!
- If you see a capital E then there is an error.
- you don't really need to enter 2 cards that are blackjack
This is for entertainment only! so I hope this has been interesting and if you have built this that it works well for you. Happy tinkering...