Spaces:
Runtime error
Runtime error
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') | |