1
0

refactor: use better algo for determining highest

This commit is contained in:
2026-06-04 20:17:40 +08:00
parent 4c77056e13
commit f72cf52d10
+5 -5
View File
@@ -34,16 +34,16 @@ class FirstGuess(Scoring):
class HighestAmount(Scoring): class HighestAmount(Scoring):
def __init__(self): def __init__(self):
self.shares: set[ItemShare] = set() self.max: ItemShare | None = None
def calculate_score(self, item: ItemShare) -> int: def calculate_score(self, item: ItemShare) -> int:
self.shares.add(item) if self.max is None or item.count > self.max.count:
self.max = item
return 0 return 0
def calculate_end_score(self) -> ItemShare | None: def calculate_end_score(self) -> ItemShare | None:
highest = max(self.shares, key=lambda s: s.count) self.max.score = 1
highest.score = 1 return self.max
return highest
class FirstThenHighest(Scoring): class FirstThenHighest(Scoring):