282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
+
+
+
+
|
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 {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()
self.increment_round()
|
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
+
-
+
-
+
+
+
+
+
+
+
-
+
|
player.tick()
self.increment_tick()
# 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")
log_dbc = log_db.cursor()
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))
|