Index: bunco.py ================================================================== --- bunco.py +++ bunco.py @@ -9,33 +9,15 @@ } def TurnInProgress(): return -1 -def roll_dice(name, current_round, roll_count): +def roll_dice(): dice = [] - result = 0 - - desired_num = current_round % 6 - desired_num = 6 if desired_num == 0 else desired_num - for _ in range(3): dice.append(random.randint(1,6)) - - if all(die == desired_num for die in dice): - # Bunco! - result = 21 - elif all(die == dice[0] for die in dice): - # All three dice match, but not Bunco - result = 5 - else: - for die in dice: - result += 1 if die == desired_num else 0 - - print(f"In round {current_round} {name} rolled {dice} = {result}") - return result - + return dice class Player: fuzzydie_holder = None def __init__(self, name, dex, math, speed): @@ -51,10 +33,11 @@ self.turn_progress = 0 self.current_streak = 0 self.max_fuzzydie_streak = 0 self.current_fuzzydie_streak = 0 self.rolled_bunco = False + self.current_roll = [] def __repr__(self): return f"" \ + f"\troll counts\t{self.round_roll_counts}>" @@ -63,10 +46,39 @@ self.round_scores.append(0) self.round_roll_counts.append(0) self.personal_roll_scores.append(0) self.turn_progress = 0 self.current_streak = 0 + + def score_last_roll(self, current_round): + desired_num = current_round % 6 + desired_num = 6 if desired_num == 0 else desired_num + + roll_score = 0 + + if all(die == desired_num for die in self.current_roll): + # Bunco! + roll_score = 21 + elif all(die == self.current_roll[0] for die in self.current_roll): + # All three dice match, but not Bunco + roll_score = 5 + else: + for die in self.current_roll: + roll_score += 1 if die == desired_num else 0 + + if roll_score > 0: + self.current_streak += 1 + self.max_streak = max(self.current_streak, self.max_streak) + self.round_scores[current_round - 1] += roll_score + self.personal_roll_scores[current_round - 1] += roll_score + if roll_score == 21: + self.bunco_count += 1 + self.rolled_bunco = True + else: + self.current_streak = 0 + + return roll_score def tick(self, current_round): result = TurnInProgress() if self.fuzzydie_holder is self: @@ -84,28 +96,18 @@ # TODO: Incorporate ROLL SPEED stat self.turn_progress += random.randint(12,25) elif self.turn_progress < 75: # Reading the numbers # TODO: Incorporate MATH COMPREHENSION stat + if not self.current_roll: + self.current_roll = roll_dice() + self.round_roll_counts[current_round - 1] += 1 self.turn_progress += random.randint(12,25) else: - # Finished rolling - self.round_roll_counts[current_round - 1] += 1 - roll_result = roll_dice(self.name, current_round, self.round_roll_counts[current_round - 1]) - - if roll_result > 0: - self.current_streak += 1 - self.max_streak = max(self.current_streak, self.max_streak) - self.round_scores[current_round - 1] += roll_result - self.personal_roll_scores[current_round - 1] += roll_result - if roll_result == 21: - self.bunco_count += 1 - self.rolled_bunco = True - else: - self.current_streak = 0 - - result = roll_result + # Finished reading the numbers -- good job, eyeballs and brain! + result = self.score_last_roll(current_round) + self.current_roll = [] self.turn_progress = 0 return result class Table: def __init__(self): @@ -265,6 +267,13 @@ while max(self.tables[0].team1_score, self.tables[0].team2_score) < 21: self.tick() print("\n\n\t\tB U N C O !!!\n\n") + # Finish up scoring for any players that have unscored rolls + for player in self.players: + if player.current_roll: + print(f"Finishing up: {player}") + while player.current_roll: + player.tick(self.current_round) + self.print_status()