Advertisement
makispaiktis

Poker Combinations

Jan 4th, 2022 (edited)
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 18.29 KB | None | 0 0
  1. from itertools import combinations
  2. from random import shuffle
  3. import operator
  4.  
  5.  
  6. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~ AUXILIARY FUNCTIONS ~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  9.  
  10. # Create a class Card
  11. class Card:
  12.     def __init__(self, symbol, value):
  13.         self.symbol = symbol
  14.         self.value = value
  15.  
  16. # 1. Create the cards
  17. def createCards():
  18.     symbols = ["heart", "diamond", "spade", "club"]
  19.     values = list(range(1, 14))
  20.     cards = list()
  21.     for symbol in symbols:
  22.         for value in values:
  23.             card = Card(symbol, value)
  24.             cards.append(card)
  25.     shuffle(cards)
  26.     shuffle(cards)
  27.     return cards
  28.  
  29. # 2. Print a list (values)
  30. def valuePrint(cards):
  31.     for card in cards:
  32.         print(card.value)
  33.  
  34. # 3. Print all the stats of a card
  35. def allPrint(cards):
  36.     string = ""
  37.     for card in cards:
  38.         string += card.symbol + " " + str(card.value) + ", "
  39.     print(string)
  40.  
  41. # 4. Sort by value
  42. def sortByValue(cards):
  43.     return sorted(cards, key=lambda card: card.value, reverse=True)
  44.  
  45. # 5. Count the unique values
  46. def uniqueValues(cards):
  47.     sorted_cards = sortByValue(cards)
  48.     uniqueCounter = 1
  49.     uniqueList = [sorted_cards[0]]
  50.     for i in range(1, len(sorted_cards)):
  51.         if sorted_cards[i].value != sorted_cards[i-1].value:
  52.             uniqueCounter += 1
  53.             uniqueList.append(sorted_cards[i])
  54.     # print("Unique values:", uniqueCounter)
  55.     return uniqueCounter #, uniqueList
  56.  
  57. # 6. Values
  58. def values(cards):
  59.     valuesList = []
  60.     for card in cards:
  61.         valuesList.append(card.value)
  62.     return valuesList
  63.  
  64. # 7. Symbols
  65. def symbols(cards):
  66.     symbolsList = []
  67.     for card in cards:
  68.         symbolsList.append(card.symbol)
  69.     return symbolsList
  70.  
  71. # 8. Print all the stats of a card combination
  72. def combinationPrint(combinationString, cards):
  73.     string = combinationString
  74.     for card in cards:
  75.         string += card.symbol + " " + str(card.value) + ", "
  76.     print(string)
  77. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  78. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  79.  
  80.  
  81.  
  82.  
  83. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~~~~~~~
  84. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ KENTA ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~ (6) ~
  85. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~~~~~~~
  86.  
  87. # Kenta (Input = 5 cards)
  88. def isKenta(cards):
  89.  
  90.     # Bad Cases
  91.     if len(cards) != 5:
  92.         print("No kenta with less or more than 5 cards")
  93.         return False, []
  94.     if uniqueValues(cards) != 5:
  95.         return False, []
  96.     else:
  97.         # Nice and valid cases
  98.         pentada = cards
  99.         valuesPentada = values(pentada)
  100.         unique = uniqueValues(pentada)
  101.         if valuesPentada == [13, 12, 11, 10, 1]:
  102.             return True, pentada
  103.         else:
  104.             if valuesPentada[0] - valuesPentada[4] == 4:
  105.                 return True, pentada
  106.     return False, []
  107.  
  108.  
  109. # Input = 7 cards
  110. def containsKenta(cards):
  111.  
  112.     pentades = list(combinations(cards, 5))
  113.     for pentada in pentades:
  114.         pentada = list(pentada)
  115.         flag, kenta = isKenta(pentada)
  116.         if flag == True:
  117.             #print("!!!! There is a kenta !!!!")
  118.             return flag, kenta
  119.     return False, []
  120. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  121. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  122.  
  123.  
  124.  
  125. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~~~~~~~
  126. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ STRAIGHT FLUSH ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~ (2) ~
  127. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~~~~~~~
  128.  
  129. # Straight Flush (Input = 5 cards)
  130. def isStraightFlush(cards):
  131.     pentada = cards
  132.     flag, kenta = isKenta(pentada)
  133.     if flag == True:
  134.         # Now, I know if this pentada is a kenta and I check the symbols
  135.         pentadaSymbols = symbols(pentada)
  136.         flag2 = True
  137.         for i in range(len(pentadaSymbols)-1):
  138.             if pentadaSymbols[i] != pentadaSymbols[i+1]:
  139.                 flag2 = False
  140.                 return False, []
  141.         if flag2 == True:
  142.             return True, pentada
  143.     return False, []
  144.  
  145. # Input = 7 cards
  146. def containsStraightFlush(cards):
  147.     pentades = list(combinations(cards, 5))
  148.     for pentada in pentades:
  149.         pentada = list(pentada)
  150.         flag, straight = isStraightFlush(pentada)
  151.         if flag == True:
  152.             #print("!!!! There is a straight flush !!!!")
  153.             return True, pentada
  154.     return False, []
  155. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  156. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  157.  
  158.  
  159.  
  160. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~~~~~~~
  161. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FLUSH ROYAL ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~ (1) ~
  162. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~~~~~~~
  163.  
  164. # Flush Royal
  165. def isFlushRoyal(pentada):
  166.     flag, straight = isStraightFlush(pentada)
  167.     if flag == True:
  168.         # It will be flush royal, if the values are [13, 12, 11, 10, 1]
  169.         if values(straight) == [13, 12, 11, 10, 1]:
  170.             print("YEAH")
  171.             return True, straight
  172.     return False, []
  173.  
  174. def containsFlushRoyal(cards):
  175.     pentades = list(combinations(cards, 5))
  176.     for pentada in pentades:
  177.         pentada = list(pentada)
  178.         flag, flush = isFlushRoyal(pentada)
  179.         if flag == True:
  180.             #print("!!!! There is a flush royal !!!!")
  181.             return True, pentada
  182.     return False, []
  183.  
  184. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  185. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  186.  
  187.  
  188. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~~~~~~~
  189. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FLUSH ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~ (5) ~
  190. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~~~~~~~
  191.  
  192. # Full house (input = 5 cards)
  193. def isFlush(pentada):
  194.     if len(pentada) != 5:
  195.         print("Error while using function '", isFlush.__name__, "'")
  196.         return "-1000", "-1000"
  197.     else:
  198.         pentadaSymbols = symbols(pentada)
  199.         flag2 = True
  200.         for i in range(len(pentadaSymbols) - 1):
  201.             if pentadaSymbols[i] != pentadaSymbols[i + 1]:
  202.                 flag2 = False
  203.                 return False, []
  204.         if flag2 == True:
  205.             return True, pentada
  206.  
  207. # Input = 7 cards
  208. def containsFlush(cards):
  209.     pentades = list(combinations(cards, 5))
  210.     for pentada in pentades:
  211.         pentada = list(pentada)
  212.         flag, flush = isFlush(pentada)
  213.         if flag == True:
  214.             #print("!!!! There is a flush !!!!")
  215.             return True, pentada
  216.     return False, []
  217. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  218. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  219.  
  220. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~~~~~~~
  221. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ KARE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~ (3) ~
  222. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~~~~~~~
  223.  
  224. # Kare (Input = 4 cards)
  225. def isKare(tetrada):
  226.     if len(tetrada) != 4:
  227.         print("Error while using function '", isKare.__name__, "'")
  228.         return "-1000", "-1000"
  229.     else:
  230.         valuesTetrada = values(tetrada)
  231.         flag = True
  232.         for i in range(len(valuesTetrada)-1):
  233.             if valuesTetrada[i] != valuesTetrada[i+1]:
  234.                 flag = False
  235.                 return False, []
  236.         if flag == True:
  237.             return True, tetrada
  238.  
  239. # Input = 7 cards
  240. def containsKare(cards):
  241.     tetrades = list(combinations(cards, 4))
  242.     for tetrada in tetrades:
  243.         tetrada = list(tetrada)
  244.         flag, kare = isKare(tetrada)
  245.         if flag == True:
  246.             # print("!!!! There is a kare !!!!")
  247.             return True, kare
  248.     return False, []
  249.  
  250. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  251. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  252.  
  253.  
  254.  
  255. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~~~~~~~
  256. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FULL HOUSE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~ (4) ~
  257. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~~~~~~~
  258.  
  259. # Full House (Input = 5 cards)
  260. def isFullHouse(pentada):
  261.     if len(pentada) != 5:
  262.         print("Error while using function '", isFullHouse.__name__, "'")
  263.         return "-1000", "-1000"
  264.  
  265.     v = values(pentada)
  266.     # I want 3 values equal and 2 values equal (remember that this list is sorted)
  267.     # Sth in this form: [12, 12, 12, 5, 5] or [12, 12, 5, 5, 5]
  268.     if (v[0] == v[1]) and (v[3] == v[4]) and ((v[2] == v[1]) or (v[2] == v[3])):
  269.         return True, pentada
  270.     return False, []
  271.  
  272. # Input = 7 cards
  273. def containsFullHouse(cards):
  274.     pentades = list(combinations(cards, 5))
  275.     for pentada in pentades:
  276.         pentada = list(pentada)
  277.         flag, full = isFullHouse(pentada)
  278.         if flag == True:
  279.             # print("!!!! There is a flush !!!!")
  280.             return True, pentada
  281.     return False, []
  282.  
  283.  
  284. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  285. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  286.  
  287.  
  288.  
  289.  
  290. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~~~~~~~
  291. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TRIFYLLIA ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~ (7) ~
  292. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~~~~~~~
  293.  
  294. # Trifyllia (Input = 3 cards)
  295. def isTrifyllia(triada):
  296.     if len(triada) != 3:
  297.         print("Error while using function '" + isTrifyllia.__name__ + "'")
  298.         return "-1000", "-1000"
  299.     v = values(triada)
  300.     if v[0] == v[1] and v[1] == v[2]:
  301.         return True, triada
  302.     return False, []
  303.  
  304. # Input = 7 cards
  305. def containsTrifyllia(cards):
  306.     triades = list(combinations(cards, 3))
  307.     for triada in triades:
  308.         triada = list(triada)
  309.         flag, trifyllia = isTrifyllia(triada)
  310.         if flag == True:
  311.             # print("!!!! There is a trifyllia !!!!")
  312.             return True, triada
  313.     return False, []
  314.  
  315. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  316. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  317.  
  318.  
  319.  
  320. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~~~~~~~
  321. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ TWO PAIRS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~ (8) ~
  322. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~~~~~~~
  323.  
  324. # Two pairs (Input - 4 cards)
  325. def isPairs(tetrada):
  326.     if len(tetrada) != 4:
  327.         print("Error while using function '" + isPairs().__name__ + "'")
  328.         return "-1000", "-1000"
  329.     v = values(tetrada)
  330.     if v[0] == v[1] and v[2] == v[3] and v[1] != v[2]:
  331.         return True, tetrada
  332.     return False, []
  333.  
  334. # Input = 7 cards
  335. def containsPairs(cards):
  336.     tetrades = list(combinations(cards, 4))
  337.     for tetrada in tetrades:
  338.         tetrada = list(tetrada)
  339.         flag, pairs = isPairs(tetrada)
  340.         if flag == True:
  341.             # print("!!!! There are 2 pairs !!!!")
  342.             return True, tetrada
  343.     return False, []
  344.  
  345.  
  346.  
  347. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~~~~~~~
  348. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DIFYLLIA ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~ (9) ~
  349. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    ~~~~~~~
  350.  
  351. # Difyllia (Input = 2 cards)
  352. def isDifyllia(diada):
  353.     if len(diada) != 2:
  354.         print("Error while using function '" + isTrifyllia.__name__ + "'")
  355.         return "-1000", "-1000"
  356.     v = values(diada)
  357.     if v[0] == v[1]:
  358.         return True, diada
  359.     return False, []
  360.  
  361. # Input = 7 cards
  362. def containsDifyllia(cards):
  363.     diades = list(combinations(cards, 2))
  364.     for diada in diades:
  365.         diada = list(diada)
  366.         flag, difyllia = isDifyllia(diada)
  367.         if flag == True:
  368.             # print("!!!! There is a difyllia !!!!")
  369.             return True, diada
  370.     return False, []
  371.  
  372. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  373. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  374.  
  375.  
  376.  
  377.  
  378.  
  379. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  380. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  381.  
  382. # Testing functions
  383. def testing(sorted_first7):
  384.  
  385.     print()
  386.     print("**********************************************************************")
  387.     allPrint(sorted_first7)
  388.     print("**********************************************************************")
  389.     testing(sorted_first7)
  390.  
  391.     # 1. Testing Flush Royal
  392.     flag, royal = containsFlushRoyal(sorted_first7)
  393.     print("1. Contains Flush Royal?", flag)
  394.     combinationPrint("Flush royal is:", royal)
  395.     print()
  396.     # 2. Testing Straight Flush
  397.     flag, straight = containsStraightFlush(sorted_first7)
  398.     print("2. Contains Straight Flush?", flag)
  399.     combinationPrint("Straight Flush is:", straight)
  400.     print()
  401.     # 3. Testing Kare
  402.     flag, kare = containsKare(sorted_first7)
  403.     print("3. Contains Kare?", flag)
  404.     combinationPrint("Flush is:", kare)
  405.     print()
  406.     # 4. Testing Full House
  407.     flag, full = containsFullHouse(sorted_first7)
  408.     print("4. Contains Full House?", flag)
  409.     combinationPrint("Full House is:", full)
  410.     print()
  411.     # 5. Testing Flush
  412.     flag, flush = containsFlush(sorted_first7)
  413.     print("5. Contains Flush?", flag)
  414.     combinationPrint("Flush is:", flush)
  415.     print()
  416.     # 6. Testing Kenta
  417.     flag, kenta = containsKenta(sorted_first7)
  418.     print("6. Contains Kenta?", flag)
  419.     combinationPrint("Kenta is:", kenta)
  420.     print()
  421.     # 7. Testing Trifyllia
  422.     flag, trifyllia = containsTrifyllia(sorted_first7)
  423.     print("7. Contains Trifyllia?", flag)
  424.     combinationPrint("Trifyliia is:", trifyllia)
  425.     print()
  426.     # 8. Testing Pairs
  427.     flag, pairs = containsPairs(sorted_first7)
  428.     print("8. Contains pairs?", flag)
  429.     combinationPrint("Pairs are:", pairs)
  430.     print()
  431.     # 9. Testing Trifyllia
  432.     flag, difyllia = containsDifyllia(sorted_first7)
  433.     print("9. Contains Difyllia?", flag)
  434.     combinationPrint("Difyliia is:", difyllia)
  435.     print()
  436.  
  437.  
  438.  
  439. # DETERMINE BIGGEST COMBINATION
  440. def determine(sorted_first7):
  441.  
  442.     allPrint(sorted_first7)
  443.     index = 0
  444.  
  445.     # Begin the process of searching
  446.  
  447.     # 1. Flush Royal
  448.     flag, winner_comb = containsFlushRoyal(sorted_first7)
  449.     if flag == True:
  450.         print("        FLUSH ROYAL")
  451.         return index
  452.     index += 1
  453.     # 2. Straight Flush
  454.     flag, winner_comb = containsStraightFlush(sorted_first7)
  455.     if flag == True:
  456.         print("        STRAIGHT FLUSH")
  457.         return index
  458.     index += 1
  459.  
  460.     # 3. Kare
  461.     flag, winner_comb = containsKare(sorted_first7)
  462.     if flag == True:
  463.         print("        Kare")
  464.         return index
  465.     index += 1
  466.     # 4. Full House
  467.     flag, winner_comb = containsFullHouse(sorted_first7)
  468.     if flag == True:
  469.         print("        FULL HOUSE")
  470.         return index
  471.     index += 1
  472.  
  473.     # 5. Flush
  474.     flag, winner_comb = containsFlush(sorted_first7)
  475.     if flag == True:
  476.         print("        FLUSH")
  477.         return index
  478.     index += 1
  479.     # 6. Kenta
  480.     flag, winner_comb = containsKenta(sorted_first7)
  481.     if flag == True:
  482.         print("        KENTA")
  483.         return index
  484.     index += 1
  485.  
  486.     # 7. TRIFYLLIA
  487.     flag, winner_comb = containsTrifyllia(sorted_first7)
  488.     if flag == True:
  489.         print("        Trifyllia")
  490.         return index
  491.     index += 1
  492.     # 8. 2 Pairs
  493.     flag, winner_comb = containsPairs(sorted_first7)
  494.     if flag == True:
  495.         print("        2 Pairs")
  496.         return index
  497.     index += 1
  498.     # 9. Difyllia
  499.     flag, winner_comb = containsDifyllia(sorted_first7)
  500.     if flag == True:
  501.         print("        Difyllia")
  502.         return index
  503.     index += 1
  504.     # 10. High Card
  505.     print("        High Card")
  506.     return index
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  515. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  516. #  ~~~~~~~~~~~~~~~~~~~~~~~~~ MAIN FUNCTION ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  517. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  518. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  519.  
  520. # Create data for storing each winner combination
  521. # Flush royal(1) goes in index 0, straight flush(2) in 2, ...., difyllia(9) goes in 8, high card(10) goes in 9
  522. named_combinations = [" Flush Royal  ", "Straight Flush", "     Kare     ", "  Full House  ", "    Flush     ", "    Kenta     ", "  Trifyllia   ", "   2 Pairs    ", "   Difyllia   ", "  High Card   "]
  523. winner_combinations = [0 for i in range(10)]
  524. N = 10**5
  525. for round in range(1, N+1):
  526.     print("~~~~~~~~ Round " + str(round) + " ~~~~~~~~")
  527.     cards = createCards()
  528.     first7 = cards[0:7]
  529.     sorted_first7 = sortByValue(first7)
  530.     index = determine(sorted_first7)
  531.     winner_combinations[index] += 1
  532.     print()
  533.  
  534. # Print Stats
  535. print()
  536. print("~~~~~~~~ Winner Combinations List ~~~~~~~~")
  537. print(winner_combinations)
  538. print()
  539. for i in range(len(winner_combinations)):
  540.     named = named_combinations[i]
  541.     times_won = winner_combinations[i]
  542.     percentage100 = 100 * (times_won / N)
  543.     print(named + ": " + str(times_won) + " wins  =  " + str(percentage100) + "%")
  544.  
  545.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement