FIX: Fixed the score not updating when a dice was removed. should fix losing despite having a full board
This commit is contained in:
parent
77ae0cde5d
commit
2b621ae030
@ -22,20 +22,22 @@ class KnucklebonesGame:
|
|||||||
column -= 1 # Adjust for 1-based index
|
column -= 1 # Adjust for 1-based index
|
||||||
self.columns[player][column].insert(0, dice) # Place at the top of the column
|
self.columns[player][column].insert(0, dice) # Place at the top of the column
|
||||||
self.clear_matching_dice(player, dice, column)
|
self.clear_matching_dice(player, dice, column)
|
||||||
self.calculate_score(player)
|
self.calculate_score()
|
||||||
|
|
||||||
def clear_matching_dice(self, player, dice, column):
|
def clear_matching_dice(self, player, dice, column):
|
||||||
opponent = self.other_player()
|
opponent = self.other_player()
|
||||||
opponent_column = self.columns[opponent][column]
|
opponent_column = self.columns[opponent][column]
|
||||||
self.columns[opponent][column] = [d for d in opponent_column if d != dice]
|
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):
|
||||||
total_score = 0
|
for player in self.players:
|
||||||
for column in self.columns[player]:
|
total_score = 0
|
||||||
if column:
|
for column in self.columns[player]:
|
||||||
column_score = sum(column) * len(column)
|
if column:
|
||||||
total_score += column_score
|
column_score = sum(column) * len(column)
|
||||||
self.scores[player] = total_score
|
total_score += column_score
|
||||||
|
self.scores[player] = total_score
|
||||||
|
|
||||||
def next_turn(self):
|
def next_turn(self):
|
||||||
self.turn = (self.turn + 1) % 2
|
self.turn = (self.turn + 1) % 2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user