Bunco Simulator

Check-in [5b68c7]
Overview
Comment:Refine separation of roll/read turn phases; fix scoring of unread rolls at end of round
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 5b68c775743655cc1fd2d19811ff6e95fffacbd76f02ac806c95c3caa082ccdb
User & Date: joel on 2018-11-20 04:06:01
Other Links: manifest | tags
Context
2018-11-20
04:34
Resolve ties at end of round (fixes [f08d3a4db3]). Track table numbers. check-in: d7edd6 user: joel tags: trunk
04:06
Refine separation of roll/read turn phases; fix scoring of unread rolls at end of round check-in: 5b68c7 user: joel tags: trunk
03:20
Adjust player display string check-in: 663177 user: joel tags: trunk
Changes

Modified bunco.py from [28f635] to [5ff744].

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
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
57
58
59
60
61
62
63
64
65
66
67





























68
69
70
71
72
73
74
# Test
import csv, random

teammate = {
    1: 3,
    2: 4,
    3: 1,
    4: 2
}

def TurnInProgress():
    return -1

def roll_dice(name, current_round, roll_count):
    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


class Player:
    fuzzydie_holder = None

    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.bunco_count = 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

    
    def __repr__(self):
        return f"<Player {self.name}: " \
            + f"\tscores\t\t{self.round_scores}>" \
            + f"\troll counts\t{self.round_roll_counts}>"

    def prep_new_round(self):
        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 tick(self, current_round):
        result = TurnInProgress()

        if self.fuzzydie_holder is self:
            self.current_fuzzydie_streak += 1
            self.max_fuzzydie_streak = max(self.max_fuzzydie_streak, self.current_fuzzydie_streak)













|

<
<
<
<
<


<
<
<
<
<
<
<
<
<
<
<
<
|
<



















>












>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Test
import csv, random

teammate = {
    1: 3,
    2: 4,
    3: 1,
    4: 2
}

def TurnInProgress():
    return -1

def roll_dice():
    dice = []





    for _ in range(3):
        dice.append(random.randint(1,6))












    return dice


class Player:
    fuzzydie_holder = None

    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.bunco_count = 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 prep_new_round(self):
        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:
            self.current_fuzzydie_streak += 1
            self.max_fuzzydie_streak = max(self.max_fuzzydie_streak, self.current_fuzzydie_streak)
82
83
84
85
86
87
88



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
        elif self.turn_progress < 50:
            # Rolling the dice
            # 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



            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
            self.turn_progress = 0
        return result

class Table:
    def __init__(self):
        self.team1_score = 0
        self.team2_score = 0







>
>
>


|
<
<
|
<
<
<
<
<
<
<
<
<
|
<
<







94
95
96
97
98
99
100
101
102
103
104
105
106


107









108


109
110
111
112
113
114
115
        elif self.turn_progress < 50:
            # Rolling the dice
            # 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 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):
        self.team1_score = 0
        self.team2_score = 0
263
264
265
266
267
268
269







270
    def play_one_round(self):
        # Go until one of the head table teams reaches 21 pts
        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")
        







        self.print_status()







>
>
>
>
>
>
>

265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
    def play_one_round(self):
        # Go until one of the head table teams reaches 21 pts
        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()