A Raspberry Pi Rain Man in the Making

We see a lot of Raspberry Pis used to play games, but this is something entirely different from the latest RetroPie build. This Raspberry Pi is learning how to read playing cards, with the goal of becoming the ultimate card counting blackjack player.

If [Taxi-guy] hasn’t named his project Rain Man, we humbly suggest that he does so. Because a Pi that can count into a six-deck shoe would be quite a thing, even though it would never be allowed anywhere near a casino. Hurdle number one in counting cards is reading them, and [Taxi-guy] has done a solid job of leveraging the power of OpenCV on a Pi 3 for the task. His description in the video below is very detailed, but the approach is simple: find the cards in a PiCam image of the playing field using a combination of thresholding and contouring. Then, with the cards isolated, compare the rank and suit in the upper left corner of the rotated card image to prototype images to identify the card. The Pi provides enough horsepower to quickly identify an arbitrary number of non-overlapping cards; we assume [Taxi-guy] will have to address overlapping cards and decks that use different fonts at some point.

We’re keen to see this Pi playing blackjack someday. As he’s coding that up, he may want to look at algorithmic approaches to blackjack strategies, and the real odds of beating the house.

Continue reading “A Raspberry Pi Rain Man in the Making”

Evolutionary algorithms computes the best blackjack strategy


Don’t want to learn about evolutionary algorithms the usual way, by generating sentences from random letters, or randomly placing pixels to generate the Mona Lisa? Then make your own evolutionary algorithm! With blackjack!

[Brian] has been playing around with evolutionary algorithms, and wanted a task that’s well suited for optimization. He chose blackjack, because of the limited number of hands that can be dealt to the player (32) and low number of hands the dealer can have (10).

Even with the low number of initial conditions for the player and the dealer, there are still 4.562 x 10^192 possible combinations of hands, so brute forcing a blackjack strategy would require the computational power of the entire planet. An easier way to compute a good strategy is an evolutionary algorithm, implemented by [Brian] with the Watchmaker Java library.

For each generation in [Brian]’s program, a 32×10 grid was generated, one cell each for possible player’s hands against the dealer’s hand. In each cell, the computer put a ‘hit’, ‘stay’, or ‘double down’, and played thousands of hands with that strategy. The best strategies were bred and eventually [Brian] ended up with a good blackjack strategy.

The resulting best strategy is pretty good – using his strategy, he can walk out of an Atlantic City casino with 96% of the money he arrived with.

Maggy, locked and loaded


Some readers may remember [Paul] from his project Jak, the blackjack robot; but his interests have moved toward coil gun creation. Maggy, his latest weapon, may not be the prettiest of coil gun we’ve seen, or the most environmentally friendly, but does look to be promising. Featuring a triple stage, logic based accelerator instead of the typical single stage, it can fire a 10 gram projectile (theoretically) up to 85 km/h! Check out how he’s gone from a single pistol to his current monster on his site, and a video of his work in progress after the jump. Continue reading “Maggy, locked and loaded”

Jak, the blackjack robot

[Paul] sent in this Robotfest 2009 exhibition competition entry. This is Jak, the blackjack robot. This seems to be a convergence between a digital game of blackjack and a physical game. The robot scans each card as it deals them and feeds the data to a piece of software that tracks each players hand.  The players select their next step on the screen and the robot responds appropriately. They have won 1st place in the Ontario competition and are now going to the international level. Jak wins a round in the video, but we didn’t see him celebrating. Come on guys, make him flash some lights or talk some trash.