57 lines
1.4 KiB
Python
Executable File
57 lines
1.4 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
|
|
class HandClass:
|
|
def __init__(self, bid, cards):
|
|
self.bid = bid
|
|
self.cards = cards
|
|
self.cardnumbers = []
|
|
self.numbers = {}
|
|
x = [*cards]
|
|
for i in x:
|
|
self.cardnumbers.append(self.cardnumber(i))
|
|
if i not in self.numbers:
|
|
self.numbers[self.cardnumber(i)] = 1
|
|
else:
|
|
self.numbers[self.cardnumber(i)] += 1
|
|
x.sort(key=self.cardnumber, reverse=True)
|
|
self.sorted = x
|
|
self.handstrength()
|
|
|
|
def cardnumber(self, x: str):
|
|
if x.isdigit():
|
|
return int(x)
|
|
if x == "T":
|
|
return 10
|
|
if x == "J":
|
|
return 11
|
|
if x == "Q":
|
|
return 12
|
|
if x == "K":
|
|
return 13
|
|
if x == "A":
|
|
return 14
|
|
return 0
|
|
|
|
def handstrength(self):
|
|
print(self.numbers.values())
|
|
if len(set(self.cardnumbers)) == 1:
|
|
return 5
|
|
if len(self.numbers)==2:
|
|
print("2")
|
|
def __str__(self):
|
|
return f"Cards: {self.cards} Bid: {self.bid}, sorted: {self.sorted}, num {self.cardnumbers}, numcount {self.numbers}"
|
|
|
|
def __repr__(self):
|
|
return str(self)
|
|
|
|
|
|
with open("data.txt") as file:
|
|
lines = [line.rstrip() for line in file]
|
|
|
|
hands = []
|
|
for line in lines:
|
|
halves = line.split(" ")
|
|
hands.append(HandClass(halves[1], halves[0]))
|
|
print(hands[-1])
|