Advertisement
dmesticg

Untitled

Jun 4th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. import collections
  2.  
  3. def bubbleSort(arr):
  4. isSorted = False
  5. while not(isSorted):
  6. for i in range(len(arr) - 1):
  7. for j in range(len(arr) - 1 - i):
  8. if arr[j] > arr[j+1]:
  9. arr[j], arr[j+1] = arr[j+1],arr[j]
  10. else:
  11. isSorted = True
  12. return (arr)
  13.  
  14. def occur(cards):
  15. counter = collections.Counter(cards)
  16. largest = [0,0]
  17. largest2 = [0,0]
  18. for key in counter:
  19. occur = counter[key]
  20. if occur > largest2[1]:
  21. if occur > largest[1]:
  22. largest2 = largest
  23. largest = [key,counter[key]]
  24. else:
  25. largest2 = [key,counter[key]]
  26. if largest[1] + largest2[1] == 5:
  27. return(7)
  28. elif largest[1] in [1,2,3]:
  29. return(largest[1] + 1)
  30. else:
  31. return(8)
  32.  
  33. # if 2 highest are the same, is a 2 pair :DDDDD
  34.  
  35. def flush(cards):
  36. counter = collections.Counter(cards)
  37. if len(counter) == 1:
  38. return(True)
  39. return(False)
  40.  
  41. def straight(cards):
  42. if cards[4] - cards[0] == 4:
  43. return(True)
  44. return(False)
  45.  
  46. def royal(cards):
  47. royal = [1,10,11,12,13]
  48. if cards == royal:
  49. return(True)
  50. return(False)
  51.  
  52.  
  53. values = [1,2,2,4,5]
  54. suits = [1,1,2,1,1]
  55.  
  56. #score: 1(highcard)|2(pair)|3(two pair)|4(three of a kind)|5(straight)|6(flush)|7(full house)|8(four of a kind)|9(straight flush)|10(royal flush|
  57.  
  58. def handLogic(values,suits):
  59. values = bubbleSort(values)
  60. suits = bubbleSort(suits)
  61. occurances = occur(values)
  62. if occurances == 2:
  63. if flush(suits) == 5:
  64. if straight(values):
  65. return(9)
  66. if royal(values):
  67. return(10)
  68. return(6)
  69. if straight(values):
  70. return(5)
  71. return(1)
  72. return(occurances)
  73.  
  74.  
  75. print("score: " + str(handLogic(values,suits)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement