FIX: Fixed the score not updating when a dice was removed. should fix losing despite having a full board

This commit is contained in:
Dan 2024-07-04 12:26:24 -04:00
parent 77ae0cde5d
commit 2b621ae030

View File

@ -22,14 +22,16 @@ 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):
def calculate_score(self):
for player in self.players:
total_score = 0
for column in self.columns[player]:
if column: