Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,64 +1,71 @@
|
|
1 |
import streamlit as st
|
2 |
import random
|
|
|
3 |
|
4 |
-
# Define the
|
5 |
-
player_cards = {
|
6 |
-
"Player 1": {
|
7 |
-
"name": "Player 1",
|
8 |
-
"sketch": "π©",
|
9 |
-
"score": 0,
|
10 |
-
"mime": ""
|
11 |
-
},
|
12 |
-
"Player 2": {
|
13 |
-
"name": "Player 2",
|
14 |
-
"sketch": "π¨",
|
15 |
-
"score": 0,
|
16 |
-
"mime": ""
|
17 |
-
}
|
18 |
-
}
|
19 |
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
# Define the possible actions
|
24 |
-
actions = ["jump", "dance", "sing", "sleep", "laugh", "cry", "eat", "drink", "run", "swim"]
|
25 |
|
26 |
# Define the Streamlit app
|
27 |
-
def app():
|
28 |
-
st.set_page_config(page_title="Mime Game", page_icon="π", layout="wide")
|
29 |
-
st.title("Mime Game")
|
30 |
-
st.sidebar.write("# Player Cards")
|
31 |
-
for player, attributes in player_cards.items():
|
32 |
-
st.sidebar.write(f"## {player}")
|
33 |
-
st.sidebar.write(f"Name: {attributes['name']}")
|
34 |
-
st.sidebar.write(f"Sketch: {attributes['sketch']}")
|
35 |
-
st.sidebar.write(f"Score: {attributes['score']}")
|
36 |
-
st.sidebar.write("# Game Settings")
|
37 |
-
num_rounds = st.sidebar.slider("Number of rounds to play", 1, 10, 5)
|
38 |
-
# Start the game when the user clicks the "Play Game" button
|
39 |
-
if st.button("Play Game"):
|
40 |
-
# Play the game for the specified number of rounds
|
41 |
-
for i in range(num_rounds):
|
42 |
-
st.write(f"Round {i+1}")
|
43 |
-
for player, attributes in player_cards.items():
|
44 |
-
# Ask the player to perform an action using mime or mimicry
|
45 |
-
st.write(f"{attributes['sketch']} {attributes['name']}, it's your turn to perform an action using mime or mimicry.")
|
46 |
-
mime = st.text_input("Enter your mime/mimicry")
|
47 |
-
attributes["mime"] = mime
|
48 |
-
# Randomly select an action and ask the other player to guess it
|
49 |
-
action = random.choice(actions)
|
50 |
-
st.write(f"The action is: {action}")
|
51 |
-
for player, attributes in player_cards.items():
|
52 |
-
if attributes["mime"] == action:
|
53 |
-
attributes["score"] += 1
|
54 |
-
st.write(f"{attributes['sketch']} {attributes['name']} guessed the action correctly! π")
|
55 |
-
else:
|
56 |
-
st.write(f"{attributes['sketch']} {attributes['name']} failed to guess the action.")
|
57 |
-
# Display the final scores
|
58 |
-
st.write("# Final Scores")
|
59 |
-
for player, attributes in player_cards.items():
|
60 |
-
st.write(f"{attributes['sketch']} {attributes['name']}: {attributes['score']} points")
|
61 |
-
|
62 |
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import random
|
3 |
+
import pandas as pd
|
4 |
|
5 |
+
# Define the game mechanics
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
def generate_scenario():
|
8 |
+
scenarios = ['You are a superhero saving the world from a meteorite',
|
9 |
+
'You are a pirate searching for treasure on a deserted island',
|
10 |
+
'You are a chef trying to win a cooking competition',
|
11 |
+
'You are a detective solving a murder case']
|
12 |
+
return random.choice(scenarios)
|
13 |
+
|
14 |
+
def calculate_score(slider_values):
|
15 |
+
bluffing_score = slider_values[0]
|
16 |
+
deduction_score = slider_values[1]
|
17 |
+
humor_score = slider_values[2]
|
18 |
+
memory_score = slider_values[3]
|
19 |
+
roleplay_score = slider_values[4]
|
20 |
+
|
21 |
+
total_score = bluffing_score + deduction_score + humor_score + memory_score + roleplay_score
|
22 |
+
return total_score
|
23 |
+
|
24 |
+
def play_game(slider_values):
|
25 |
+
scenario = generate_scenario()
|
26 |
+
st.write('Act out the following scenario: ' + scenario)
|
27 |
+
total_score = calculate_score(slider_values)
|
28 |
+
st.write('Your total score is: ' + str(total_score))
|
29 |
+
|
30 |
+
# Save game history to a dataframe
|
31 |
+
game_history_df = pd.DataFrame({'Scenario': [scenario],
|
32 |
+
'Bluffing': [slider_values[0]],
|
33 |
+
'Deduction': [slider_values[1]],
|
34 |
+
'Humor': [slider_values[2]],
|
35 |
+
'Memory': [slider_values[3]],
|
36 |
+
'Roleplay': [slider_values[4]],
|
37 |
+
'Total Score': [total_score]})
|
38 |
+
return game_history_df
|
39 |
+
|
40 |
+
def save_game_history(game_history_df):
|
41 |
+
game_history_df.to_csv('game_history.csv', index=False)
|
42 |
+
st.write('Game history saved!')
|
43 |
+
st.write(game_history_df)
|
44 |
+
|
45 |
+
def run_simulations():
|
46 |
+
simulations = 1000
|
47 |
+
total_scores = []
|
48 |
+
for i in range(simulations):
|
49 |
+
slider_values = [random.randint(1, 10) for i in range(5)]
|
50 |
+
total_score = calculate_score(slider_values)
|
51 |
+
total_scores.append(total_score)
|
52 |
+
st.write('Average score from ' + str(simulations) + ' simulations: ' + str(sum(total_scores)/len(total_scores)))
|
53 |
|
|
|
|
|
54 |
|
55 |
# Define the Streamlit app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
+
st.title('Acting Game Mechanics')
|
58 |
+
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.')
|
59 |
+
|
60 |
+
slider_values = [st.slider('Bluffing', 1, 10, 5),
|
61 |
+
st.slider('Deduction', 1, 10, 5),
|
62 |
+
st.slider('Humor', 1, 10, 5),
|
63 |
+
st.slider('Memory', 1, 10, 5),
|
64 |
+
st.slider('Roleplay', 1, 10, 5)]
|
65 |
+
|
66 |
+
if st.button('Play'):
|
67 |
+
game_history_df = play_game(slider_values)
|
68 |
+
save_game_history(game_history_df)
|
69 |
+
|
70 |
+
if st.button('Run simulations'):
|
71 |
+
run_simulations()
|