From f72cf52d1081b772b87492b879a71fd276733ba5 Mon Sep 17 00:00:00 2001 From: Poleric Date: Thu, 4 Jun 2026 20:17:40 +0800 Subject: [PATCH] refactor: use better algo for determining highest --- src/inventory_wars/scoring.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/inventory_wars/scoring.py b/src/inventory_wars/scoring.py index 832c436..f58d56b 100644 --- a/src/inventory_wars/scoring.py +++ b/src/inventory_wars/scoring.py @@ -34,16 +34,16 @@ class FirstGuess(Scoring): class HighestAmount(Scoring): def __init__(self): - self.shares: set[ItemShare] = set() + self.max: ItemShare | None = None 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 def calculate_end_score(self) -> ItemShare | None: - highest = max(self.shares, key=lambda s: s.count) - highest.score = 1 - return highest + self.max.score = 1 + return self.max class FirstThenHighest(Scoring):