awacke1 commited on
Commit
8b1d587
Β·
1 Parent(s): 707417d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -28
app.py CHANGED
@@ -1,31 +1,28 @@
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],
@@ -35,37 +32,89 @@ def play_game(slider_values):
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()
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import random
3
  import pandas as pd
4
+ from datetime import datetime
5
 
6
  # Define the game mechanics
7
 
8
  def generate_scenario():
9
+ scenarios = ['🦸 You are a superhero saving the world from a meteorite',
10
+ 'πŸ΄β€β˜ οΈ You are a pirate searching for treasure on a deserted island',
11
+ 'πŸ‘¨β€πŸ³ You are a chef trying to win a cooking competition',
12
+ 'πŸ•΅οΈ You are a detective solving a murder case']
13
  return random.choice(scenarios)
14
 
15
  def calculate_score(slider_values):
16
+ bluffing_score, deduction_score, humor_score, memory_score, roleplay_score = slider_values
 
 
 
 
17
 
18
  total_score = bluffing_score + deduction_score + humor_score + memory_score + roleplay_score
19
  return total_score
20
 
21
  def play_game(slider_values):
22
  scenario = generate_scenario()
23
+ st.write('🎭 Act out the following scenario: ' + scenario)
24
  total_score = calculate_score(slider_values)
25
+ st.write('🎯 Your total score is: ' + str(total_score))
26
 
27
  # Save game history to a dataframe
28
  game_history_df = pd.DataFrame({'Scenario': [scenario],
 
32
  'Memory': [slider_values[3]],
33
  'Roleplay': [slider_values[4]],
34
  'Total Score': [total_score]})
35
+
36
+ # Append to existing game history
37
+ try:
38
+ existing_game_history = pd.read_csv('game_history.csv')
39
+ game_history_df = pd.concat([existing_game_history, game_history_df], ignore_index=True)
40
+ except:
41
+ pass
42
+
43
  return game_history_df
44
 
45
  def save_game_history(game_history_df):
46
  game_history_df.to_csv('game_history.csv', index=False)
47
+ st.write('πŸ“ Game history saved!')
48
  st.write(game_history_df)
49
 
50
+ def save_simulation_results(simulation_results_df):
51
+ filename = datetime.now().strftime('%Y-%m-%d %H-%M-%S') + '.csv'
52
+ simulation_results_df.to_csv(filename, index=False)
53
+ st.write('πŸ“ Simulation results saved!')
54
+ st.write(simulation_results_df)
55
+
56
+ def run_simulations(num_simulations):
57
  total_scores = []
58
+ simulation_results_df = pd.DataFrame(columns=['Scenario', 'Bluffing', 'Deduction', 'Humor', 'Memory', 'Roleplay', 'Total Score'])
59
+ for i in range(num_simulations):
60
  slider_values = [random.randint(1, 10) for i in range(5)]
61
  total_score = calculate_score(slider_values)
62
  total_scores.append(total_score)
63
+ scenario = generate_scenario()
64
+ simulation_results_df = simulation_results_df.append({'Scenario': scenario,
65
+ 'Bluffing': slider_values[0],
66
+ 'Deduction': slider_values[1],
67
+ 'Humor': slider_values[2],
68
+ 'Memory': slider_values[3],
69
+ 'Roleplay': slider_values[4],
70
+ 'Total Score': total_score}, ignore_index=True)
71
+ st.write('🎲 Average score from ' + str(num_simulations) + ' simulations: ' + str(sum(total_scores)/len(total_scores)))
72
+ st.write(simulation_results_df)
73
+ save_simulation_results(simulation_results_df)
74
 
75
 
76
  # Define the Streamlit app
77
 
78
+ st.title('🎭 Acting Game Mechanics')
79
+ 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.')
80
+
81
+ slider_values = [st.slider('πŸƒ Bluffing', 1, 10, 5),
82
+ st.slider('πŸ•΅οΈ Deduction', 1, 10, 5),
83
+ st.slider('πŸ˜‚ Humor', 1, 10, 5),
84
+ st.slider('🧠 Memory', 1, 10, 5),
85
+ st.slider('πŸ‘₯ Roleplay', 1, 10, 5)]
86
+
87
+ if st.button('🎭 Play'):
88
+ game_history_df = play_game(slider_values)
89
+ save_game_history(game_history_df)
90
+
91
+ if st.button('🎲 Run simulations'):
92
+ num_simulations = st.slider('πŸ” Number of simulations', 1, 100000, 1000)
93
+ run_simulations(num_simulations)
94
 
95
+ if st.button('πŸ“ Show all game history'):
96
+ try:
97
+ game_history_df = pd.read_csv('game_history.csv')
98
+ st.write(game_history_df)
99
+ except:
100
+ st.write('No game history found')
101
 
102
+ if st.button('πŸ“ Download game history'):
103
+ try:
104
+ game_history_df = pd.read_csv('game_history.csv')
105
+ filename = 'game_history_' + datetime.now().strftime('%Y-%m-%d %H-%M-%S') + '.csv'
106
+ game_history_df.to_csv(filename, index=False)
107
+ st.write('πŸ“ Game history downloaded!')
108
+ st.write(game_history_df)
109
+ except:
110
+ st.write('No game history found')
111
 
112
+ if st.button('πŸ“ Download simulation results'):
113
+ try:
114
+ simulation_results_df = pd.read_csv('simulation_results.csv')
115
+ filename = 'simulation_results_' + datetime.now().strftime('%Y-%m-%d %H-%M-%S') + '.csv'
116
+ simulation_results_df.to_csv(filename, index=False)
117
+ st.write('πŸ“ Simulation results downloaded!')
118
+ st.write(simulation_results_df)
119
+ except:
120
+ st.write('No simulation results found')