Flip7Statistics / app.py
PaulMartrenchar's picture
Remove logs
165ea49
raw
history blame
1.63 kB
import gradio as gr
from collections import Counter
def bump_probability(drawn_card_strings, special_cards_drawn):
TOTAL_SPECIAL_CARDS = 15
special_cards_remaining = TOTAL_SPECIAL_CARDS - special_cards_drawn
# Convert strings from checkbox input to integers
drawn_cards = [int(card) for card in drawn_card_strings]
total_counts = {i: i for i in range(13)}
total_counts[0] = 1 # fix 0 to have 1 copy
count_drawn = Counter(drawn_cards)
bump_cards_remaining = 0
total_remaining_cards = special_cards_remaining
for card_value in range(13):
total_available = total_counts[card_value]
already_drawn = count_drawn.get(card_value, 0)
remaining = total_available - already_drawn
total_remaining_cards += remaining
if already_drawn > 0:
bump_cards_remaining += remaining
if total_remaining_cards == 0:
return "0.0% (no cards remaining)"
probability = bump_cards_remaining / total_remaining_cards
return f"{probability * 100:.2f}% chance of bumping"
# Gradio interface
card_choices = [str(i) for i in range(13)]
iface = gr.Interface(
fn=bump_probability,
inputs=[
gr.CheckboxGroup(choices=card_choices, label="Cards you have (select all drawn cards)", type="value"),
gr.Slider(minimum=0, maximum=15, step=1, label="Number of special cards drawn")
],
outputs="text",
title="Flip 7 Bump Probability Calculator",
description="Select the number cards you've drawn and how many special cards you've already drawn to see the probability of bumping on your next card."
)
iface.launch()