awacke1 commited on
Commit
f6ea017
Β·
verified Β·
1 Parent(s): ae70b08

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -7
app.py CHANGED
@@ -7,14 +7,22 @@ MAX_DICE = 5
7
  MAX_PLAYERS = 4
8
  DICE_SIDES = 6
9
 
 
 
 
 
 
10
  # Game functions
11
  def roll_dice(n):
12
  return np.random.randint(1, DICE_SIDES + 1, n)
13
 
14
- def display_dice(dice):
15
- # Use the length of the dice array to determine how many emojis to display
16
- return " ".join([emojize(":game_die:") for _ in dice])
17
-
 
 
 
18
  def update_scores(scores, dice):
19
  for i, score in enumerate(scores):
20
  if dice[i] == DICE_SIDES:
@@ -42,11 +50,12 @@ scores = [0 for _ in range(players)]
42
  rolled_dice = roll_dice(players * dice_count)
43
  scores = update_scores(scores, rolled_dice)
44
 
45
- # Display game board for all players
46
  for player in range(players):
47
  start_index = player * dice_count
48
  end_index = start_index + dice_count
49
- st.write(f"Player {player + 1} rolled: {display_dice(rolled_dice[start_index:end_index])}")
 
50
 
51
  st.write(f"Scores: {scores}")
52
 
@@ -58,5 +67,6 @@ if st.button("Roll again"):
58
  for player in range(players):
59
  start_index = player * dice_count
60
  end_index = start_index + dice_count
61
- st.write(f"Player {player + 1} rolled: {display_dice(rolled_dice[start_index:end_index])}")
 
62
  st.write(f"Scores: {scores}")
 
7
  MAX_PLAYERS = 4
8
  DICE_SIDES = 6
9
 
10
+ # Predefined list of rhyming names with emojis for players
11
+ player_names = [
12
+ ("Mick 🎀", "Rick πŸš€", "Nick 🧊", "Vick 🌿")
13
+ ]
14
+
15
  # Game functions
16
  def roll_dice(n):
17
  return np.random.randint(1, DICE_SIDES + 1, n)
18
 
19
+ def display_dice(dice_rolls):
20
+ # Display emojis based on the number rolled
21
+ emoji_str = ""
22
+ for roll in dice_rolls:
23
+ emoji_str += emojize(":game_die:") + " " * roll + " " # Adjust this line for a more accurate representation
24
+ return emoji_str.strip()
25
+
26
  def update_scores(scores, dice):
27
  for i, score in enumerate(scores):
28
  if dice[i] == DICE_SIDES:
 
50
  rolled_dice = roll_dice(players * dice_count)
51
  scores = update_scores(scores, rolled_dice)
52
 
53
+ # Display game board for all players with rhyming names
54
  for player in range(players):
55
  start_index = player * dice_count
56
  end_index = start_index + dice_count
57
+ player_name = player_names[player % len(player_names)] # Loop through player_names if players > len(player_names)
58
+ st.write(f"{player_name} rolled: {display_dice(rolled_dice[start_index:end_index])}")
59
 
60
  st.write(f"Scores: {scores}")
61
 
 
67
  for player in range(players):
68
  start_index = player * dice_count
69
  end_index = start_index + dice_count
70
+ player_name = player_names[player % len(player_names)]
71
+ st.write(f"{player_name} rolled: {display_dice(rolled_dice[start_index:end_index])}")
72
  st.write(f"Scores: {scores}")