This commit is contained in:
Lauri Jesmin
2023-12-08 19:06:27 +02:00
parent 70f8426e22
commit c3c7a5ad15

View File

@@ -38,9 +38,26 @@ class HandClass:
def handstrength(self):
print(self.numbers.values())
if len(set(self.cardnumbers)) == 1:
return 6
if 1 in self.numbers:
numofj = self.numbers[1]
else:
numofj = 0
nc = sorted(list(self.numbers.values()))
self.nc1 = nc
if numofj > 0 and len(nc) > 1:
for i in range(0, len(nc)):
if nc[i] == numofj:
nc.pop(i)
break
nc[-1] += numofj
self.nc2 = nc
if len(nc) == 1:
return 6
if len(nc) == 2 and nc[1] == 4:
return 5
if len(nc) == 2 and nc[1] == 3:
@@ -54,7 +71,7 @@ class HandClass:
return 0
def __str__(self):
return f"Cards: {self.cards} Bid: {self.bid}, sorted: {self.sorted}, num {self.cardnumbers}, numcount {self.numbers}, str: {self.strength}"
return f"Cards: {self.cards} Bid: {self.bid}, sorted: {self.sorted}, num {self.cardnumbers}, numcount {self.numbers}, str: {self.strength}, n1: {self.nc1}, n2 {self.nc2}"
def __repr__(self):
return str(self)
@@ -65,27 +82,24 @@ def compare(c1, c2):
return 1
if c1.strength < c2.strength:
return -1
# if c1.strength == 0 and c2.strength == 0:
# for i in range(0, len(c1.sorted)):
# if c1.sorted[i] > c2.sorted[i]:
# return 1
# if c1.sorted[i] < c2.sorted[i]:
# return -1
# return 0
if c1.strength == c2.strength:
for i in range(0, len(c1.cardnumbers)):
if c1.cardnumbers[i] > c2.cardnumbers[i]:
return 1
if c1.cardnumbers[i] < c2.cardnumbers[i]:
return -1
return 0
return 0
with open("data.txt") as file:
with open("data2.txt") as file:
lines = [line.rstrip() for line in file]
hands = []
for line in lines:
if line == '':
print("Tühi rida")
continue
print(line)
halves = line.split(" ")
hands.append(HandClass(halves[1], halves[0]))
print(hands[-1])
@@ -101,5 +115,6 @@ for h in h2:
count += 1
total += count*int(h.bid)
print(h)
print(f"{h.bid} {count*int(h.bid)}")
print(total)