pooleli
This commit is contained in:
@@ -1,30 +1,46 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
|
||||
class HandClass:
|
||||
def __init__(self, bid, cards):
|
||||
self.bid = bid
|
||||
self.cards = cards
|
||||
self.cardnumbers = []
|
||||
self.numbers = {}
|
||||
x = [*cards]
|
||||
x.sort(key=self.cardumber, reverse=True)
|
||||
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 cardumber(self, x: str):
|
||||
def cardnumber(self, x: str):
|
||||
if x.isdigit():
|
||||
return int(x)
|
||||
if x == "T":
|
||||
return 10
|
||||
if x == 'J':
|
||||
if x == "J":
|
||||
return 11
|
||||
if x == 'Q':
|
||||
if x == "Q":
|
||||
return 12
|
||||
if x == 'K':
|
||||
if x == "K":
|
||||
return 13
|
||||
if x == 'A':
|
||||
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}"
|
||||
return f"Cards: {self.cards} Bid: {self.bid}, sorted: {self.sorted}, num {self.cardnumbers}, numcount {self.numbers}"
|
||||
|
||||
def __repr__(self):
|
||||
return str(self)
|
||||
@@ -35,6 +51,6 @@ with open("data.txt") as file:
|
||||
|
||||
hands = []
|
||||
for line in lines:
|
||||
halves = line.split(' ')
|
||||
halves = line.split(" ")
|
||||
hands.append(HandClass(halves[1], halves[0]))
|
||||
print(hands[-1])
|
||||
|
||||
Reference in New Issue
Block a user