Advertisement
dmesticg

Untitled

Jun 5th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 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. scorelist = [2,4,8]
  16. counter = collections.Counter(cards)
  17. largest = [0,0]
  18. largest2 = [0,0]
  19. for key in counter:
  20. occur = counter[key]
  21. if occur > largest2[1]:
  22. if occur > largest[1]:
  23. largest2 = largest
  24. largest = [key,occur]
  25. else:
  26. largest2 = [key,occur]
  27. num = max([largest[0],largest2[0]])
  28. if largest[1] == 3 and largest2[1] == 2:
  29. return(7,largest[0])
  30. elif largest[1] == largest2[1]:
  31. return(3,num)
  32. elif largest[1] in [2,3,4]:
  33. return(scorelist[[2,3,4].index(largest[1])],num )
  34. return(1,num)
  35.  
  36.  
  37. def flush(cards):
  38. counter = collections.Counter(cards)
  39. if len(counter) == 1:
  40. return(True,max(cards))
  41. return(False,max(cards))
  42.  
  43. def straight(cards):
  44. if cards[4] - cards[0] == 4:
  45. return(True,max(cards))
  46. return(False,max(cards))
  47.  
  48. def royal(cards):
  49. royal = [1,10,11,12,13]
  50. if cards == royal:
  51. return(True,13)
  52. return(False,13)
  53.  
  54.  
  55. values = [1,2,2,4,5]
  56. suits = [1,1,2,1,1]
  57.  
  58. #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|
  59.  
  60. def handLogic(values,suits):
  61. values = bubbleSort(values)
  62. suits = bubbleSort(suits)
  63. occurances = occur(values)
  64. if occurances == 2:
  65. if flush(suits) == 5:
  66. if straight(values):
  67. return(9)
  68. if royal(values):
  69. return(10)
  70. return(6)
  71. if straight(values):
  72. return(5)
  73. return(1)
  74. return(occurances)
  75.  
  76.  
  77. print("score: " + str(handLogic(values,suits)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement