Bunco Simulator

Check-in [eb8331]
Overview
Comment:Track player wins and losses
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: eb833168ae16949b1fbfeba450f2277c36f5e2301233ba2b7b68bc8f7fb9bc6c
User & Date: joel on 2018-11-22 13:41:49
Other Links: manifest | tags
Context
2018-11-22
16:02
Add functions to track average contribution, average and median scores check-in: 1de0c8 user: joel tags: trunk
13:41
Track player wins and losses check-in: eb8331 user: joel tags: trunk
13:24
Add function to spit out overview of game in Excel (start on [927402827e]) check-in: d20fed user: joel tags: trunk
Changes

Modified bunco.py from [87116e] to [481d05].

21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

48
49
50
51
52
53
54
        self.math_comprehension = math
        self.roll_speed = speed
        self.max_streak = 0
        self.round_bunco_counts = [0]
        self.round_scores = [0]
        self.round_roll_counts = [0]
        self.personal_roll_scores = [0]

        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"<Player {self.name}: " \
            + f"\tscores\t\t{self.round_scores}>" \
            + 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.round_bunco_counts.append(0)

        self.turn_progress = 0
        self.current_streak = 0

    def score_last_roll(self):
        desired_num = Game.current_round() % 6
        desired_num = 6 if desired_num == 0 else desired_num
    







>




















>







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
        self.math_comprehension = math
        self.roll_speed = speed
        self.max_streak = 0
        self.round_bunco_counts = [0]
        self.round_scores = [0]
        self.round_roll_counts = [0]
        self.personal_roll_scores = [0]
        self.round_wins = [0]
        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"<Player {self.name}: " \
            + f"\tscores\t\t{self.round_scores}>" \
            + 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.round_bunco_counts.append(0)
        self.round_wins.append(0)
        self.turn_progress = 0
        self.current_streak = 0

    def score_last_roll(self):
        desired_num = Game.current_round() % 6
        desired_num = 6 if desired_num == 0 else desired_num
    
203
204
205
206
207
208
209




210
211
212
213
214
215
216
            # Team 2 (odds) lost
            losers = self.players[1::2]
            # Player 2 move to spot 3
            self.players[3] = self.players[2]
        # Replace middle two players
        self.players[1:3] = new_players
        return losers




    
    def prep_new_round(self):
        self.team1_score = 0
        self.team2_score = 0
        self.active_player = -1
        for player in self.players:
            player.prep_new_round()







>
>
>
>







205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
            # Team 2 (odds) lost
            losers = self.players[1::2]
            # Player 2 move to spot 3
            self.players[3] = self.players[2]
        # Replace middle two players
        self.players[1:3] = new_players
        return losers

    def notch_wins(self):
        for player in self.winners():
            player.round_wins[Game.current_round() - 1] = 1
    
    def prep_new_round(self):
        self.team1_score = 0
        self.team2_score = 0
        self.active_player = -1
        for player in self.players:
            player.prep_new_round()
363
364
365
366
367
368
369


370
371
372
373
374
375
376
        # Settle ties at each table by doing a roll-off as many times as needed
        for table in self.tables:
            log('all', f"{table}: Team 1 {table.team1_score} pts, Team 2 {table.team2_score} pts")
            while table.team1_score == table.team2_score:
                log('all', f"{table} having a roll-off to resolve a tie")
                table.roll_off()
                log('all', f"{table}: Team 1 {table.team1_score} pts, Team 2 {table.team2_score} pts")


    
log_db = sqlite3.connect("bunco.sqlite")
log_dbc = log_db.cursor()

def run_query(*args):
    log_dbc.execute(*args)
    log_db.commit()







>
>







369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
        # Settle ties at each table by doing a roll-off as many times as needed
        for table in self.tables:
            log('all', f"{table}: Team 1 {table.team1_score} pts, Team 2 {table.team2_score} pts")
            while table.team1_score == table.team2_score:
                log('all', f"{table} having a roll-off to resolve a tie")
                table.roll_off()
                log('all', f"{table}: Team 1 {table.team1_score} pts, Team 2 {table.team2_score} pts")
            
            table.notch_wins()
    
log_db = sqlite3.connect("bunco.sqlite")
log_dbc = log_db.cursor()

def run_query(*args):
    log_dbc.execute(*args)
    log_db.commit()

Modified bunco_app.py from [e250da] to [b9a3c7].

118
119
120
121
122
123
124
125



126


127
128
129
130
    for n, player in enumerate(g.players):
        row = n + 3
        ws.write(row, 0, player.name, row_heading)

        for r in range(g.current_round()):
            col = r + 1
            ws.write(row, col, player.round_scores[r], score_style)




        ws.write(row, end_col + 1, sum(player.round_scores), total_style)


        ws.write(row, end_col + 4, sum(player.round_bunco_counts), total_style)
        ws.write(row, end_col + 5, sum(player.round_roll_counts), total_style)

    wb.close()







|
>
>
>

>
>




118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
    for n, player in enumerate(g.players):
        row = n + 3
        ws.write(row, 0, player.name, row_heading)

        for r in range(g.current_round()):
            col = r + 1
            ws.write(row, col, player.round_scores[r], score_style)
        
        # derive losses from wins
        losses = [int(not x) for x in player.round_wins]

        ws.write(row, end_col + 1, sum(player.round_scores), total_style)
        ws.write(row, end_col + 2, sum(player.round_wins), total_style)
        ws.write(row, end_col + 3, sum(losses), total_style)
        ws.write(row, end_col + 4, sum(player.round_bunco_counts), total_style)
        ws.write(row, end_col + 5, sum(player.round_roll_counts), total_style)

    wb.close()