We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,650 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Help with game program

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

3
Contributors
6
Replies
2 Weeks
Discussion Span
5 Years Ago
Last Updated
8
Views
Chunkymonkey
Newbie Poster
4 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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':
            suit = "Spades"
        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)
Ene Uran
Posting Virtuoso
1,830 posts since Aug 2005
Reputation Points: 676
Solved Threads: 255
Skill Endorsements: 7

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.

BearofNH
Posting Whiz
323 posts since May 2007
Reputation Points: 94
Solved Threads: 48
Skill Endorsements: 1

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

Chunkymonkey
Newbie Poster
4 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

Ene Uran
Posting Virtuoso
1,830 posts since Aug 2005
Reputation Points: 676
Solved Threads: 255
Skill Endorsements: 7

ok thanks

Chunkymonkey
Newbie Poster
4 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

Chunkymonkey
Newbie Poster
4 posts since Apr 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.1581 seconds using 2.81MB