alexspy Alex's .py alexspy

Hi, I'm Alex. I created this Python blog to show people the latest games and code I'm working on, along with explanations and examples for anyone looking to learn more about Python, CGI / server-side programming, or just internet game development in general. Let me know what you think, and thanks for visiting!



Jan 14, 2012 : one_card_poker.py

Here's a breakdown of how the one_card_poker.py source code works, in 5 easy steps...

In its simplest form, playing a hand of poker consists of 4 basic phases: dealing, betting, comparing and paying out. Note that phases 1, 3 & 4 can occur automatically, but phase 2 (betting) requires the player to make a decision.

Therefore, the computer program can only carry the game up to the point where we ask player 1 what his bet is before it has to pause and wait for an answer. As we know from our other games, pausing inside of an actively running python program is not practical in a static html CGI environment. Instead, we choose to end the python program, print a display to the html screen asking the user for his bet and utilize branched recursion to finish phases 3 & 4 after the information we need to continue has been entered. This results in two different kind of displays, which we call frames, that could be printed to the game's (html) GUI: a dealing frame & an evaluation frame. As you'll see in the code below, distinguishing between the two is critical for the program to run successfully.
  1. Check if the program is being asked to excecute a dealing frame or an evaluation frame...



  2. Define a few decision-making functions (AI) for the dealer based on the strength of the cards he can see and some other game variables...



  3. Define a function that checks to make sure both player's bets are real, possible bets that make sense...



  4. If this is a dealing frame, then execute the dealing branch of the program and print the dealing screen to the html display...



  5. If this is an evaluation frame, then execute the eval branch of the program and print the eval screen to the html display...






Here's some other great python blogs I like to check out:

Nadia Alramli's Blog
The "Invent with Python" Blog
Carter Sande's Blog