Spaces:
Runtime error
Runtime error
File size: 5,350 Bytes
707417d da8a7b7 707417d da8a7b7 707417d da8a7b7 707417d da8a7b7 707417d da8a7b7 707417d da8a7b7 707417d da8a7b7 707417d da8a7b7 707417d da8a7b7 707417d da8a7b7 707417d da8a7b7 707417d da8a7b7 707417d da8a7b7 707417d da8a7b7 |
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 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 114 115 116 117 118 119 120 121 |
import streamlit as st
import random
import pandas as pd
from datetime import datetime
# Define the game mechanics
def generate_scenario():
scenarios = ['π¦Έ You are a superhero saving the world from a meteorite',
'π΄ββ οΈ You are a pirate searching for treasure on a deserted island',
'π¨βπ³ You are a chef trying to win a cooking competition',
'π΅οΈ You are a detective solving a murder case']
return random.choice(scenarios)
def calculate_score(slider_values):
bluffing_score, deduction_score, humor_score, memory_score, roleplay_score = slider_values
total_score = bluffing_score + deduction_score + humor_score + memory_score + roleplay_score
return total_score
def play_game(slider_values):
scenario = generate_scenario()
st.write('π Act out the following scenario: ' + scenario)
total_score = calculate_score(slider_values)
st.write('π― Your total score is: ' + str(total_score))
# Save game history to a dataframe
game_history_df = pd.DataFrame({'Scenario': [scenario],
'Bluffing': [slider_values[0]],
'Deduction': [slider_values[1]],
'Humor': [slider_values[2]],
'Memory': [slider_values[3]],
'Roleplay': [slider_values[4]],
'Total Score': [total_score]})
# Append to existing game history
try:
existing_game_history = pd.read_csv('game_history.csv')
game_history_df = pd.concat([existing_game_history, game_history_df], ignore_index=True)
except:
pass
return game_history_df
def save_game_history(game_history_df):
game_history_df.to_csv('game_history.csv', index=False)
st.write('π Game history saved!')
st.write(game_history_df)
def save_simulation_results(simulation_results_df):
filename = datetime.now().strftime('%Y-%m-%d %H-%M-%S') + '.csv'
simulation_results_df.to_csv(filename, index=False)
st.write('π Simulation results saved!')
st.write(simulation_results_df)
def run_simulations(num_simulations):
total_scores = []
simulation_results_df = pd.DataFrame(columns=['Scenario', 'Bluffing', 'Deduction', 'Humor', 'Memory', 'Roleplay', 'Total Score'])
for i in range(num_simulations):
slider_values = [random.randint(1, 10) for i in range(5)]
total_score = calculate_score(slider_values)
total_scores.append(total_score)
scenario = generate_scenario()
simulation_results_df = simulation_results_df.append({'Scenario': scenario,
'Bluffing': slider_values[0],
'Deduction': slider_values[1],
'Humor': slider_values[2],
'Memory': slider_values[3],
'Roleplay': slider_values[4],
'Total Score': total_score}, ignore_index=True)
st.write('π² Average score from ' + str(num_simulations) + ' simulations: ' + str(sum(total_scores)/len(total_scores)))
st.write(simulation_results_df)
save_simulation_results(simulation_results_df)
# Define the Streamlit app
st.title('π Acting Game Mechanics')
st.write('π― Welcome to the Acting Game Mechanics! This game measures your ability to bluff, deduce, use humor, remember details, and role-play. Drag the sliders to the left or right to adjust each skill, and click π Play to act out a scenario and receive a score.')
slider_values = [st.slider('π Bluffing', 1, 10, 5),
st.slider('π΅οΈ Deduction', 1, 10, 5),
st.slider('π Humor', 1, 10, 5),
st.slider('π§ Memory', 1, 10, 5),
st.slider('π₯ Roleplay', 1, 10, 5)]
if st.button('π Play'):
game_history_df = play_game(slider_values)
save_game_history(game_history_df)
if st.button('π² Run simulations'):
num_simulations = st.slider('π Number of simulations', 1, 100000, 1000)
run_simulations(num_simulations)
if st.button('π Show all game history'):
try:
game_history_df = pd.read_csv('game_history.csv')
st.write(game_history_df)
except:
st.write('No game history found')
if st.button('π Download game history'):
try:
game_history_df = pd.read_csv('game_history.csv')
filename = 'game_history_' + datetime.now().strftime('%Y-%m-%d %H-%M-%S') + '.csv'
game_history_df.to_csv(filename, index=False)
st.write('π Game history downloaded!')
st.write(game_history_df)
except:
st.write('No game history found')
if st.button('π Download simulation results'):
try:
simulation_results_df = pd.read_csv('simulation_results.csv')
filename = 'simulation_results_' + datetime.now().strftime('%Y-%m-%d %H-%M-%S') + '.csv'
simulation_results_df.to_csv(filename, index=False)
st.write('π Simulation results downloaded!')
st.write(simulation_results_df)
except:
st.write('No simulation results found')
|