Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- #poker hand either has something, or nothing.
- something = 0
- nothing = 0
- NUM_TRIALS = 100000
- #runs for given number of trials
- for i in range(0,NUM_TRIALS):
- deck = []
- hand = []
- compare = []
- skipcond = 0
- #52 cards in a deck
- for i in range(1,53):
- deck.append(i)
- #5 cards in a hand
- for i in range(0,5):
- hand.append(random.choice(deck))
- #to check for pairs and straights
- for card in hand:
- compare.append(card%13)
- #if there is a duplicate, hand is worth something (i.e. 2 of a kind).
- if len(compare)!=len(set(compare)):
- something += 1
- #no duplicates, and the max - min is 4, must be a straight.
- elif max(compare) - min(compare) == 4:
- something += 1
- print compare
- print"straight\n"
- #check for matching suits, if all match, must be a flush.
- else:
- clubMatch = 0
- spadeMatch = 0
- heartMatch = 0
- diamondMatch = 0
- for i in hand:
- if 0 < i <= 13:
- clubMatch+=1
- elif 13 < i <= 26:
- spadeMatch+=1
- elif 26 < i <= 39:
- heartMatch+=1
- elif 39 < i <= 52:
- diamondMatch+=1
- if clubMatch==5 or spadeMatch==5 or heartMatch==5 or diamondMatch==5:
- print hand
- print "flush\n"
- something +=1
- #amount of times a hand had something of value
- print something
- #amount of times a hand had nothing of value
- print NUM_TRIALS - something
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement