Index: bunco.py ================================================================== --- bunco.py +++ bunco.py @@ -35,10 +35,13 @@ def __repr__(self): return f"" \ + f"\troll counts\t{self.round_roll_counts}>" + def __str__(self): + return self.name + def prep_new_round(self): self.round_scores.append(0) self.round_roll_counts.append(0) self.personal_roll_scores.append(0) self.turn_progress = 0 @@ -105,24 +108,27 @@ 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.table_number = 0 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 f"" + def __str__(self): + if self.table_number == 1: + return "Head Table" + else: + return f"Table {self.table_number}" + def update_teammate_score(self, score): teammate = self.players[teammate_lookup[self.active_player]] teammate.round_scores[Game.current_round() - 1] += score def tick(self): @@ -222,10 +228,11 @@ for n in range(table_count): first = n * players_per_table stop_before = first + players_per_table tables[n].players = player_list[first:stop_before] + tables[n].table_number = n + 1 return tables def load_players(filename): players = [] @@ -284,16 +291,20 @@ print(f" {player.name} {player.round_scores[Game.current_round() - 1]} points, streak {player.max_streak} buncos {player.bunco_count}") def prep_next_round(self): # losers from head table move to next table headtable_losers = self.tables[0].losers() + log_table_move(headtable_losers, "lost", self.tables[0], self.tables[1]) round_winners = self.tables[1].swap_for_winners(headtable_losers) # winners from other tables move to next table for n in range(2, len(self.tables)): + log_table_move(round_winners, "won", self.tables[n-1], self.tables[n]) round_winners = self.tables[n].swap_for_winners(round_winners) + # last set of winners moves to head table + log_table_move(round_winners, "won", self.tables[-1], self.tables[0]) self.tables[0].swap_for_losers(round_winners) for table in self.tables: table.prep_new_round() @@ -316,10 +327,11 @@ # 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}") + log('all', f"{table} having a roll-off to resolve a tie") table.roll_off() self.print_status() log_db = sqlite3.connect("bunco.sqlite") @@ -328,17 +340,23 @@ def run_query(*args): log_dbc.execute(*args) log_db.commit() run_query('DROP TABLE IF EXISTS `bunco_log`') -run_query('CREATE TABLE `bunco_log` (id, tick_number, round, player_name, type, message)') +run_query('CREATE TABLE `bunco_log` (id PRIMARY KEY, tick_number, round, player_name, type, message)') def log_roll(player, dice, score): msg = f"{player.name} comprehended that [their] roll of {dice} = {score} points" query = """INSERT INTO bunco_log(tick_number, round, player_name, type, message) VALUES(?, ?, ?, ?, ?)""" - run_query(query, (Game.current_tick(), Game.current_round(), player.name, 'roll', msg)) + run_query(query, (Game.current_tick(), Game.current_round(), str(player), 'roll', msg)) + +def log_table_move(players, reason, table_from, table_to): + message = f"Having {reason} the last round, {players[0].name} and {players[1].name} move from {table_from} to {table_to}." + query = """INSERT INTO bunco_log(tick_number, round, player_name, type, message) + VALUES(?, ?, ?, ?, ?)""" + run_query(query, (Game.current_tick(), Game.current_round(), 'all', 'general', message)) def log(player, message): query = """INSERT INTO bunco_log(tick_number, round, player_name, type, message) VALUES(?, ?, ?, ?, ?)""" - run_query(query, (Game.current_tick(), Game.current_round(), player.name, 'general', message)) + run_query(query, (Game.current_tick(), Game.current_round(), str(player), 'general', message))