Advertisement
dmesticg

Untitled

Jun 17th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. def Occur(cards):
  2. scorelist = [2,4,8]
  3. counter = collections.Counter(cards)
  4. largest = [0,0]
  5. largest2 = [0,0]
  6. for key in counter:
  7. occur = counter[key]
  8. if occur > largest2[1]:
  9. if occur > largest[1]:
  10. largest2 = largest
  11. largest = [key,occur]
  12. else:
  13. largest2 = [key,occur]
  14. num = max([largest[0],largest2[0]])
  15. if largest[1] == 3 and largest2[1] == 2:
  16. return(7,largest[0])
  17. elif largest[1] == largest2[1]:
  18. return(3,num)
  19. elif largest[1] in [2,3,4]:
  20. return(scorelist[[2,3,4].index(largest[1])],num )
  21. return(1,num)
  22.  
  23.  
  24. def Flush(cards):
  25. counter = collections.Counter(cards)
  26. if len(counter) == 1:
  27. return(True,max(cards))
  28. return(False,max(cards))
  29.  
  30. def Straight(cards):
  31. if cards[4] - cards[0] == 4:
  32. return(True,max(cards))
  33. return(False,max(cards))
  34.  
  35. def Royal(cards):
  36. royal = [0,9,10,11,12]
  37. if cards == royal:
  38. return(True,13)
  39. return(False,13)
  40.  
  41. def getScore(hand):
  42. suit = bubbleSort([i[1] for i in hand])
  43. value = bubbleSort([i[0] for i in hand])
  44. occurances = Occur(value)
  45. if occurances == 2:
  46. if Flush(suit) == 5:
  47. if Straight(value):
  48. return(9)
  49. if Royal(value):
  50. return(10)
  51. return(6)
  52. if Straight(value):
  53. return(5)
  54. return(1)
  55. return(occurances)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement