@@ -108,19 +108,23 @@ self.current_roll = [] self.turn_progress = 0 return result class Table: + table_count = 0 + def __init__(self): + self.table_count += 1 + self.table_number = self.table_count self.team1_score = 0 self.team2_score = 0 self.players = [] self.active_player = -1 def __repr__(self): names = ", ".join([p.name for p in self.players]) - return "" + return f"" def tick(self, current_round): if self.active_player == -1: # First tick for the table this round self.active_player = random.randint(1, len(self.players)) - 1 @@ -138,10 +142,21 @@ self.players[teammate[self.active_player + 1]-1].round_scores[current_round - 1] += result else: self.active_player += 1 if self.active_player > (len(self.players) - 1): self.active_player = 0 + def roll_off(self, current_round): + """Attempt to settle a tie by going round the table once""" + self.active_player = 0 + + # Let the first player go until they roll for 0 points + while self.active_player == 0: + self.tick(current_round) + # Now let the rest do the same + while self.active_player != 0: + self.tick(current_round) + def losers(self): if self.team1_score > self.team2_score: return self.players[1::2] else: return self.players[0::2] @@ -273,7 +288,13 @@ for player in self.players: if player.current_roll: print(f"Finishing up: {player}") while player.current_roll: player.tick(self.current_round) + + # Settle ties at each table by doing a roll-off as many times as needed + for table in self.tables: + while table.team1_score == table.team2_score: + print(f"Roll off! {table}") + table.roll_off(self.current_round) self.print_status()