Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import io
- from collections import Counter
- #Dictionaries
- cardNames = {"♢":"D", "♡":"H", "♠":"S", "♣":"C"}
- cardColors = {"D":"White", "H":"White", "S":"Black", "C":"Black"}
- cardValues = ['2', '3', '4', '5', '6', '7', '8', '9', '10', "B", "V", "H", "A"]
- #Functions
- def basefunc(x, y, z, index = 0):
- return len([a for a in Counter(i[index] for i in x).values() if a >= y]) >=1
- def onePair(x):
- return basefunc(x,2,1)
- def threeOfAKind(x):
- return basefunc(x,3,1)
- def twoPair(x):
- return basefunc(x,2,2)
- def straight(x):
- return len([a for a in Counter(i[0] for i in x).values() if a != 1]) == 0
- def Flush(x):
- return len(Counter(i[2] for i in x).values()) == 1
- def fullHouse(x):
- return basefunc(x,2,2) and basefunc(x,3,1)
- def straightFlush(x):
- return straight(x) and Flush(x)
- def fourOfAKind(x):
- return basefunc(x,4,1)
- def royalFlush(x):
- return sorted([a for a in x[0]]) == [9,10,11,12,13]
- def checkValidity(hand, allFuncs):
- for f in allFuncs:
- if f(hand):
- return f.__name__
- return "This hand has no properties"
- def sanitiseHand(hand):
- return [(cardValues.index(str(i[:-1])),cardNames[i[-1]],cardColors[cardNames[i[-1]]]) for i in hand.split(',')[0:5]]
- #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]]
- with io.open("C:/Users/Tim/Downloads/hands.csv", "r", encoding ='utf-8') as file:
- hands = file.readlines()
- allFuncs = [fourOfAKind,straightFlush,fullHouse,fullHouse, Flush, straight, twoPair, threeOfAKind, onePair]
- aaa = 0;
- newHands = [sanitiseHand(i) for i in hands]
- for h in newHands:
- aaa = aaa+1
- print(aaa)
- print(h)
- print(checkValidity(h, allFuncs))
- print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement