simonjegou commited on
Commit
7e2cd20
·
verified ·
1 Parent(s): 56de5af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -114,8 +114,8 @@ upper_categories, lower_categories = categories[:6], categories[6:]
114
  def update_components(*inputs):
115
  # Parse inputs
116
  scorecard = {c: inputs[i] for i, c in enumerate(categories)}
117
- roll = inputs[len(categories)]
118
- dice = np.array(inputs[len(categories) + 1 :])
119
 
120
  # Compute totals
121
  scorecard_values = [0 if v == EMPTY else v for v in scorecard.values()]
@@ -123,7 +123,7 @@ def update_components(*inputs):
123
  bonus = 35 if upper > 62 else 0
124
 
125
  # Compute optimal action
126
- if (EMPTY not in dice) and (EMPTY in scorecard.values()):
127
  state = np.clip(upper, 0, 63) + sum(2 ** (6 + i) for i, c in enumerate(categories) if scorecard[c] != EMPTY)
128
  s = get_score(state)[roll]
129
  r5 = R5_indices[tuple(np.bincount(dice, minlength=7)[1:])]
@@ -172,13 +172,10 @@ This app recommends the optimal strategy for playing solitaire Yahtzee, based on
172
  with gr.Column():
173
  gr.Markdown("### Current Roll")
174
  roll_input = gr.Dropdown([1, 2, 3], label="Roll number", value=1)
175
- dice_inputs = [
176
- gr.Dropdown([EMPTY, 1, 2, 3, 4, 5, 6], label=f"Die {i+1}")
177
- for i in range(5)
178
- ]
179
  action_box = gr.Textbox(label="Optimal action", lines=2)
180
 
181
- inputs = list(score_inputs.values()) + [roll_input] + dice_inputs
182
  outputs = [upper_score, bonus_score, lower_score, total_score, action_box]
183
 
184
  for inp in inputs:
 
114
  def update_components(*inputs):
115
  # Parse inputs
116
  scorecard = {c: inputs[i] for i, c in enumerate(categories)}
117
+ roll, dice = inputs[len(categories):]
118
+ dice = np.array([int(d) for d in str(dice) if d in "123456"])
119
 
120
  # Compute totals
121
  scorecard_values = [0 if v == EMPTY else v for v in scorecard.values()]
 
123
  bonus = 35 if upper > 62 else 0
124
 
125
  # Compute optimal action
126
+ if (len(dice) == 5) and (EMPTY in scorecard.values()):
127
  state = np.clip(upper, 0, 63) + sum(2 ** (6 + i) for i, c in enumerate(categories) if scorecard[c] != EMPTY)
128
  s = get_score(state)[roll]
129
  r5 = R5_indices[tuple(np.bincount(dice, minlength=7)[1:])]
 
172
  with gr.Column():
173
  gr.Markdown("### Current Roll")
174
  roll_input = gr.Dropdown([1, 2, 3], label="Roll number", value=1)
175
+ dice_input = gr.Textbox(label="Dice values", lines=1)
 
 
 
176
  action_box = gr.Textbox(label="Optimal action", lines=2)
177
 
178
+ inputs = list(score_inputs.values()) + [roll_input, dice_input]
179
  outputs = [upper_score, bonus_score, lower_score, total_score, action_box]
180
 
181
  for inp in inputs: