Bunco Simulator

Diff

Differences From Artifact [5ff744]:

To Artifact [22520d]:


106
107
108
109
110
111
112


113


114
115
116
117
118
119
120
121

122
123
124
125
126
127
128
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124

125
126
127
128
129
130
131
132







+
+

+
+







-
+







            # 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:
    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 "<Table: " + names + ">"
        return f"<Table {self.table_number}: {names}>"

    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

        result = self.players[self.active_player].tick(current_round)
136
137
138
139
140
141
142











143
144
145
146
147
148
149
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164







+
+
+
+
+
+
+
+
+
+
+







                    self.team2_score += result

                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]
    
    def winners(self):
271
272
273
274
275
276
277
278







279
286
287
288
289
290
291
292

293
294
295
296
297
298
299
300







-
+
+
+
+
+
+
+

        
        # 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)

        
        # 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()