Index: bunco.py ================================================================== --- bunco.py +++ bunco.py @@ -1,7 +1,8 @@ # Test import csv, random, sqlite3 +from statistics import median teammate_lookup = { 0: 2, 1: 3, 2: 0, 3: 1 } fuzzydie_holder = 'x' @@ -47,10 +48,19 @@ self.personal_roll_scores.append(0) self.round_bunco_counts.append(0) self.round_wins.append(0) self.turn_progress = 0 self.current_streak = 0 + + def average_contrib_pct(self): + pcts = [] + for n in range(len(self.round_scores)): + if self.round_scores[n] > 0: + pcts.append(self.personal_roll_scores[n] / self.round_scores[n]) + else: + pcts.append(0) + return sum(pcts) / len(pcts) def score_last_roll(self): desired_num = Game.current_round() % 6 desired_num = 6 if desired_num == 0 else desired_num @@ -327,10 +337,19 @@ def print_status(self): for n, table in enumerate(self.tables): print(f"== TABLE {n+1} == Team 1:{table.team1_score} pts, Team 2:{table.team2_score} pts") for player in table.players: print(f" {player.name} {player.round_scores[Game.current_round() - 1]} points, streak {player.max_streak} buncos {sum(player.round_bunco_counts)}") + + def average_total_score(self): + all_scores = [sum(p.round_scores) for p in self.players] + return sum(all_scores) / len(all_scores) + + def median_total_score(self): + all_scores = [sum(p.round_scores) for p in self.players] + + return median(all_scores) 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])