Spaces:
Runtime error
Runtime error
import streamlit as st | |
import random | |
import pandas as pd | |
# 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 = slider_values[0] | |
deduction_score = slider_values[1] | |
humor_score = slider_values[2] | |
memory_score = slider_values[3] | |
roleplay_score = slider_values[4] | |
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]}) | |
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 run_simulations(): | |
simulations = 1000 | |
total_scores = [] | |
for i in range(simulations): | |
slider_values = [random.randint(1, 10) for i in range(5)] | |
total_score = calculate_score(slider_values) | |
total_scores.append(total_score) | |
st.write('Average score from ' + str(simulations) + ' simulations: ' + str(sum(total_scores)/len(total_scores))) | |
# 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'): | |
run_simulations() |