Hi everyone,
I'm new to daniweb and seems cool there are alot of nice helpful people on here.
With my dad we are trying to script a simple poker game on python(and tkinter).
There are 4 players ( 1 real and 3 artificiel intelligence players), each AI should be able to know if his hand is good enough to bet follow or fold and the cards should be randomised (like a usual poker game).
Which game would be easier to script? Stud or texas hold'em?
If anyone could help me or send me a show a start of script so i can get started on it ( i have seen some programs on the net but im not going to copy them)

Thankyou, Chunky

All 6 Replies

First you have to get the basic design of the deck and the hand of cards down:

``````# basic design of a card game using Python

import random

def show_hand(hand):
"""give drawn cards more detailed descriptions and then display"""
for item in hand:
rank = item[0]
suit = item[1]

if rank == 1:
rank = "Ace"
elif rank == 11:
rank = 'Jack'
elif rank == 12:
rank = 'Queen'
elif rank == 13:
rank = 'King'

if suit == 'h':
suit = "Hearts"
elif suit == 'c':
suit = "Clubs"
elif suit == 's':
elif suit == 'd':
suit = "Diamonds"

print "%s of %s" % (rank, suit)

card_list = [ (rank, suit) for suit in "hcds" for rank in range(1, 14)]

# test
# these could also be the image filenames of the cards for the GUI game
print card_list

print "-"*30

# or make the hand all cards and show detail
show_hand(card_list)

print "-"*30

# pull 5 cards
hand = card_list[:5]

# show the hand
show_hand(hand)

print "-"*30

# now shuffle cards, pull hand of 5 cards and sort hand by rank
random.shuffle(card_list)
# pull 5 cards
hand = card_list[:5]
# sort the hand by rank
hand.sort()
# show the hand
show_hand(hand)``````

You didn't say whether you meant 5-card stud or 7-card stud. I assume 7-card since only geezers like me play 5-card stud.

My guess is hold'em would be easier. (1) The number of down cards is smaller, (2) there's one fewer betting round and (3) the future outcomes are much easier to work out, since everybody shares the board instead of each getting their own cards.

As I recall there are 221 distinct sets of hole cards in HE so it's pretty easy to create a static table of all 221 combinations that tell you what to do. Ideally you'd have the AIs adjust their playing style based on their winning/losing.

Not really germane, but I guess I should mention that there is a perfect solution for a very restricted form of poker, "cold hand poker", where two players get dealt 5 cards face down, there's one betting round (no draw) then a showdown. Also, the bets must be a fixed fraction of the pot (though you can fix that fraction at any value). You might want to implement that first, just to get the display mechanisms ironed out. If you google for gimpel.zip you can download the file and look for the poker examples. Oh yes, they're written in SNOBOL4, a largely dead language that was ahead of its time. But at least (1) you're playing poker and (2) the AIs really are better than you.

Wow thankyou for the fast response,
I am decided on stud 5 card, i think it will be easier to script ( i am a newbie to python)
I don't quite understand the def show hand is it for what should be shown for each card?
Apart from that i think i know enough to get started on the game
Thankyou very much for your help, its much apreciated

Regards chunkymonkey

EDIT thankyou bear i will take a look , and it is 5 card stud i was talking about , i'm going to try and do HE and Stud and maybe integrate both into the program (so people can choose)
Thankyou

The card_list is a little cryptic and show_hand() flashes out more descriptive card names.

ok thanks

Little bump on this post, me and my dad are completly lost. We block on nearly every possible point, we have tried to define to type of hands possible but we cant seem to get it all come together and to top it all off windows vista crashed on me ( gpu driver breakdown) so i lost it all.

If anyone has an example of a poker game made with python or could start the making of one it would be much appreciated as i would like to at least see the end product but my dad and i havent got the knowledge to produce it

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.