Bunco Simulator

Diff

Differences From Artifact [bbae10]:

To Artifact [a97ef9]:


1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16
17
18
19
20

21
22
23
24
25
26
27
# Test
import csv, random, sqlite3
from statistics import median

teammate_lookup = { 0: 2, 1: 3, 2: 0, 3: 1 }

fuzzydie_holder = 'x'



def TurnInProgress():
    return -1

def roll_dice():
    dice = []
    for _ in range(3):
        dice.append(random.randint(1,6))
    return dice

class Player:
    def __init__(self, name, dex, math, speed):
        self.name = name

        self.dex = dex
        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]








>
>










|

>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Test
import csv, random, sqlite3
from statistics import median

teammate_lookup = { 0: 2, 1: 3, 2: 0, 3: 1 }

fuzzydie_holder = 'x'

table_move_callback = None

def TurnInProgress():
    return -1

def roll_dice():
    dice = []
    for _ in range(3):
        dice.append(random.randint(1,6))
    return dice

class Player:
    def __init__(self, name, phone, dex, math, speed):
        self.name = name
        self.smsnumber = phone
        self.dex = dex
        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]
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283

def load_players(filename):
    players = []

    with open(filename) as tsvfile:
        tsvreader = csv.reader(tsvfile)
        for line in tsvreader:
            players.append(Player(line[0],0,0,0))
    
    return players

class Game:
    cur_tick = 1
    cur_round = 1
    







|







272
273
274
275
276
277
278
279
280
281
282
283
284
285
286

def load_players(filename):
    players = []

    with open(filename) as tsvfile:
        tsvreader = csv.reader(tsvfile)
        for line in tsvreader:
            players.append(Player(line[0],line[1],0,0,0))
    
    return players

class Game:
    cur_tick = 1
    cur_round = 1
    
349
350
351
352
353
354
355



356
357
358
359
360



361
362
363
364



365
366
367
368
369
370
371
        
        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])



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








>
>
>





>
>
>




>
>
>







352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
        
        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])
        if callable(table_move_callback):
            for player in headtable_losers:
                table_move_callback(player, "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])
            if callable(table_move_callback):
                for player in round_winners:
                    table_move_callback(player, "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])
        if callable(table_move_callback):
            for player in round_winners:
                table_move_callback(player, "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()