Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. import random
  2. #poker hand either has something, or nothing.
  3. something = 0
  4. nothing = 0
  5. NUM_TRIALS = 100000
  6.  
  7. #runs for given number of trials
  8. for i in range(0,NUM_TRIALS):
  9.     deck = []
  10.     hand = []
  11.     compare = []
  12.     skipcond = 0
  13.  
  14.     #52 cards in a deck
  15.     for i in range(1,53):
  16.         deck.append(i)
  17.     #5 cards in a hand
  18.     for i in range(0,5):
  19.         hand.append(random.choice(deck))
  20.     #to check for pairs and straights
  21.     for card in hand:
  22.         compare.append(card%13)
  23.  
  24.     #if there is a duplicate, hand is worth something (i.e. 2 of a kind).
  25.     if len(compare)!=len(set(compare)):
  26.         something += 1
  27.     #no duplicates, and the max - min is 4, must be a straight.
  28.     elif max(compare) - min(compare) == 4:
  29.         something += 1
  30.         print compare
  31.         print"straight\n"
  32.     #check for matching suits, if all match, must be a flush.
  33.     else:
  34.         clubMatch = 0
  35.         spadeMatch = 0
  36.         heartMatch = 0
  37.         diamondMatch = 0
  38.         for i in hand:
  39.             if 0 < i <= 13:
  40.                 clubMatch+=1
  41.             elif 13 < i <= 26:
  42.                 spadeMatch+=1
  43.             elif 26 < i <= 39:
  44.                 heartMatch+=1
  45.             elif 39 < i <= 52:
  46.                 diamondMatch+=1
  47.  
  48.         if clubMatch==5 or spadeMatch==5 or heartMatch==5 or diamondMatch==5:
  49.             print hand
  50.             print "flush\n"
  51.             something +=1
  52.  
  53.  
  54. #amount of times a hand had something of value
  55. print something
  56.  
  57. #amount of times a hand had nothing of value
  58. print NUM_TRIALS - something
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement