Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import io
  3. from collections import Counter
  4.  
  5.  
  6. #Dictionaries
  7. cardNames = {"♢":"D", "♡":"H", "♠":"S", "♣":"C"}
  8. cardColors = {"D":"White", "H":"White", "S":"Black", "C":"Black"}
  9. cardValues = ['2', '3', '4', '5', '6', '7', '8', '9', '10', "B", "V", "H", "A"]
  10.  
  11. #Functions
  12. def basefunc(x, y, z, index = 0):
  13. return len([a for a in Counter(i[index] for i in x).values() if a >= y]) >=1
  14.  
  15. def onePair(x):
  16. return basefunc(x,2,1)
  17.  
  18. def threeOfAKind(x):
  19. return basefunc(x,3,1)
  20.  
  21. def twoPair(x):
  22. return basefunc(x,2,2)
  23.  
  24. def straight(x):
  25. return len([a for a in Counter(i[0] for i in x).values() if a != 1]) == 0
  26.  
  27. def Flush(x):
  28. return len(Counter(i[2] for i in x).values()) == 1
  29.  
  30. def fullHouse(x):
  31. return basefunc(x,2,2) and basefunc(x,3,1)
  32.  
  33. def straightFlush(x):
  34. return straight(x) and Flush(x)
  35.  
  36. def fourOfAKind(x):
  37. return basefunc(x,4,1)
  38.  
  39. def royalFlush(x):
  40. return sorted([a for a in x[0]]) == [9,10,11,12,13]
  41.  
  42.  
  43. def checkValidity(hand, allFuncs):
  44. for f in allFuncs:
  45. if f(hand):
  46. return f.__name__
  47. return "This hand has no properties"
  48.  
  49. def sanitiseHand(hand):
  50. return [(cardValues.index(str(i[:-1])),cardNames[i[-1]],cardColors[cardNames[i[-1]]]) for i in hand.split(',')[0:5]]
  51. #return [(cardValues.index(str(i[:-1])),cardNames[i[-1].encode('utf-8')],cardColors[cardNames[i[-1].encode('utf-8')]]) for i in hand.split(',')[0:5]]
  52.  
  53.  
  54.  
  55.  
  56. with io.open("C:/Users/Tim/Downloads/hands.csv", "r", encoding ='utf-8') as file:
  57. hands = file.readlines()
  58.  
  59. allFuncs = [fourOfAKind,straightFlush,fullHouse,fullHouse, Flush, straight, twoPair, threeOfAKind, onePair]
  60.  
  61. aaa = 0;
  62. newHands = [sanitiseHand(i) for i in hands]
  63. for h in newHands:
  64. aaa = aaa+1
  65. print(aaa)
  66. print(h)
  67. print(checkValidity(h, allFuncs))
  68. print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement