Bunco Simulator

Check-in [562309]
Overview
Comment:Summary texts for players after each round
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 5623095e1629cd7a3a1d9c2f79fce8517ac773dd85cf590932e00aa4a263c557
User & Date: joel on 2018-11-22 05:18:44
Other Links: manifest | tags
Context
2018-11-22
13:20
Log team scores at each table check-in: a09452 user: joel tags: trunk
05:18
Summary texts for players after each round check-in: 562309 user: joel tags: trunk
04:05
Evolve dashboard display check-in: 3270d1 user: joel tags: trunk
Changes

Modified bunco.py from [bdb21a] to [f4b738].

210
211
212
213
214
215
216















217
218
219
220
221
222
223
    
    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()
















def assign_teams(player_list):
    players_per_table = 4
    tables = []
    random.seed()

    if len(player_list) % players_per_table != 0:







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







210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
    
    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()
    
    def get_player_situation(self, player):
        player_index = self.players.index(player)
        if player_index % 2 == 0:
            opponents = self.players[1::2]
            opponent_score = self.team2_score
        else:
            opponents = self.players[0::2]
            opponent_score = self.team1_score
        teammate = self.players[teammate_lookup[player_index]]

        return {'teammate': teammate, 
                'opponents': opponents,
                'opponent_score': opponent_score}


def assign_teams(player_list):
    players_per_table = 4
    tables = []
    random.seed()

    if len(player_list) % players_per_table != 0:

Modified bunco_app.py from [b5e7e7] to [894897].

1
2
3
4
5
6



7
8
9
10
11
12
13
import bunco
from blessings import Terminal

t = Terminal()
g = bunco.Game("players.csv")




def print_center(before, string, after):
    col = int((t.width - len(string)) / 2) - 1
    print(f"{t.move_x(col)}{before}{string}{after}")

def display_dashboard():
    print(t.clear,t.move(0,0))
    print_center(t.bold_red,"B U N C O   S I M U L A T O R", t.normal)






>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import bunco
from blessings import Terminal

t = Terminal()
g = bunco.Game("players.csv")

def plural(str,n,suffix="s"):
    return str + suffix if n > 1 else str

def print_center(before, string, after):
    col = int((t.width - len(string)) / 2) - 1
    print(f"{t.move_x(col)}{before}{string}{after}")

def display_dashboard():
    print(t.clear,t.move(0,0))
    print_center(t.bold_red,"B U N C O   S I M U L A T O R", t.normal)
33
34
35
36
37
38
39






























g.play_one_round()
display_dashboard()

def do1():
    g.prep_next_round()
    g.play_one_round()
    display_dashboard()





































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
g.play_one_round()
display_dashboard()

def do1():
    g.prep_next_round()
    g.play_one_round()
    display_dashboard()

def summary(n):
    return summary_text(g.players[n])

def summary_text(player):
    for table in g.tables:
        if player in table.players:
            curtable = table
            break
    
    sitch = curtable.get_player_situation(player)

    if player.round_scores[g.current_round()-1] > sitch['opponent_score']:
        winloss = "beating"
    else:
        winloss = "losing to"
    foe_names = " & ".join([str(opp) for opp in sitch['opponents']])

    bunco_ct = player.round_bunco_counts[g.current_round()-1]
    if bunco_ct > 0:
        buncos = f" (& {bunco_ct} {plural('bunco',bunco_ct)}!)"
    else:
        buncos = ""

    ts = [f"Round {g.current_round()} @ {curtable} with {sitch['teammate']}:",
          f"You made {player.round_roll_counts[g.current_round()-1]} rolls,",
          f"adding {player.personal_roll_scores[g.current_round()-1]} pts{buncos}",
          f"to your team score of {player.round_scores[g.current_round()-1]},",
          f"{winloss} {foe_names}’s score of {sitch['opponent_score']}."]
    return " ".join(ts)