From 2b621ae0309bb33319547f02d5d6ea8b4e2c65ec Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 4 Jul 2024 12:26:24 -0400 Subject: [PATCH] FIX: Fixed the score not updating when a dice was removed. should fix losing despite having a full board --- modules/games/knucklebones.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/modules/games/knucklebones.py b/modules/games/knucklebones.py index 079d5da..f9c0d9d 100644 --- a/modules/games/knucklebones.py +++ b/modules/games/knucklebones.py @@ -22,20 +22,22 @@ class KnucklebonesGame: column -= 1 # Adjust for 1-based index self.columns[player][column].insert(0, dice) # Place at the top of the column self.clear_matching_dice(player, dice, column) - self.calculate_score(player) + self.calculate_score() def clear_matching_dice(self, player, dice, column): opponent = self.other_player() opponent_column = self.columns[opponent][column] self.columns[opponent][column] = [d for d in opponent_column if d != dice] + self.calculate_score() # Update score after clearing dice - def calculate_score(self, player): - total_score = 0 - for column in self.columns[player]: - if column: - column_score = sum(column) * len(column) - total_score += column_score - self.scores[player] = total_score + def calculate_score(self): + for player in self.players: + total_score = 0 + for column in self.columns[player]: + if column: + column_score = sum(column) * len(column) + total_score += column_score + self.scores[player] = total_score def next_turn(self): self.turn = (self.turn + 1) % 2