Use CherryPy add a web interface to a Python script

Lead Image © Roman Volkov, 123RF.com

Know When to Hold 'em

We show how to use Python and CherryPy to turn your Raspberry Pi and a handy display into your own online poker game.

Poker is a card game that has stood the test of time. From the saloons of the old west to the starship Enterprise, poker has been found at the center of social gatherings. As technology evolved, card games found their way into the digital realm as well.

In this article, I'll describe how to turn your Raspberry Pi and LCD TV or projector into a virtual poker table. A built-in web interface shows your hand (your cards) on your phone or tablet.

The Game of Poker

Poker ultimately comes down to creating the best possible hand of five cards [1]. The highest ranked hand wins; see the "Poker Hands" box for details. The best hand possible is a straight flush. That's five cards in order in the same suit. A straight flush from the 10 through the ace is called a royal flush. On the opposite end is the high card, where the winning hand is literally just the highest card in play. All suits are equivalent in poker; if you have a straight flush of the 2 through the 7 of hearts and I have a straight flush of 2 through 7 of clubs, then we have tied.

Poker Hands

Here are the poker hands from highest to lowest:

  • Straight flush – Five consecutive cards of the same suit.
  • Four of a kind – Four cards of the same value.
  • Full house – Three cards of the same value plus two cards of the same value (five cards total).
  • Flush – Any five cards of the same suit.
  • Straight – Five consecutive cards of any suit.
  • Three of a kind – Three cards of the same value.
  • Two pair – Two cards of the same value plus two cards of another value (four cards total).
  • Pair – Two cards of the same value.
  • High card – The highest card in play.

Betting and Money

Whenever a round of betting occurs the pot (combined money of all bets) must end "even." Any player that hasn't folded must have the same amount of money in the pot. Players that fold don't have to put any more money into the pot, but they don't get to retrieve what's already been paid.

Buy this article as PDF

Express-Checkout as PDF

Pages: 8

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content