awacke1 commited on
Commit
f13dac5
ยท
1 Parent(s): 128965c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +213 -0
app.py CHANGED
@@ -27,3 +27,216 @@ st.markdown("""
27
 
28
 
29
  """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
 
29
  """)
30
+
31
+ import streamlit as st
32
+ import random
33
+ import csv
34
+ import os
35
+
36
+ # Define the player card attributes
37
+ player_cards = {
38
+ "Player 1": {
39
+ "sketch": "๐Ÿ‘ฉ",
40
+ "character": "Nurse",
41
+ "player_board": "๐Ÿฅ",
42
+ "action_dice": "๐ŸŽฒ",
43
+ "health_tokens": "โค๏ธ",
44
+ "coin": "๐Ÿ’ฐ",
45
+ "battle_tokens": "โš”๏ธ",
46
+ "score": 0,
47
+ "trophy": ""
48
+ },
49
+ "Player 2": {
50
+ "sketch": "๐Ÿ‘จ",
51
+ "character": "Doctor",
52
+ "player_board": "๐Ÿฅ",
53
+ "action_dice": "๐ŸŽฒ",
54
+ "health_tokens": "โค๏ธ",
55
+ "coin": "๐Ÿ’ฐ",
56
+ "battle_tokens": "โš”๏ธ",
57
+ "score": 0,
58
+ "trophy": ""
59
+ }
60
+ }
61
+
62
+ # Define the health problems
63
+ health_problems = ["Flu", "COVID-19", "Diabetes", "Heart Disease", "Cancer"]
64
+
65
+ # Define the game rules
66
+ attack_range = (1, 20)
67
+ defense_range = (1, 10)
68
+
69
+ # Define the score, health tokens, and coin emoji sets
70
+ score_emojis = ["๐Ÿ”ฅ", "๐Ÿ’ฅ", "โšก๏ธ", "๐Ÿ‘Š", "๐Ÿ’ช", "๐Ÿ‹๏ธ", "๐Ÿ‘‘", "๐ŸŽ‰", "๐ŸŽŠ", "๐ŸŽ–๏ธ", "๐Ÿ…", "๐Ÿฅ‡", "๐Ÿฅˆ", "๐Ÿฅ‰"]
71
+ health_token_emojis = ["โค๏ธ", "๐Ÿ’–", "๐Ÿ’˜", "๐Ÿ’", "๐Ÿ’ž", "๐Ÿ’“", "๐Ÿ’—", "๐Ÿ’•", "๐Ÿ’Ÿ", "โฃ๏ธ", "๐Ÿฉธ", "๐Ÿงก", "๐Ÿ’›", "๐Ÿ’š", "๐Ÿ’™", "๐Ÿ’œ"]
72
+ coin_emojis = ["๐Ÿ’ฐ", "๐Ÿ’ธ", "๐Ÿ’ณ", "๐Ÿค‘", "๐Ÿ’Ž", "๐Ÿ’ท", "๐Ÿ’ต", "๐Ÿ’ฒ", "๐Ÿฆ", "๐Ÿ’น", "๐Ÿ“ˆ", "๐Ÿ“‰", "๐Ÿ’น", "๐Ÿค‘", "๐Ÿ’ฐ", "๐Ÿ’ต"]
73
+
74
+ # Create a function to play a single round of the game
75
+ def play_round(player_card, health_problem):
76
+ st.write(f"{player_card['sketch']} {player_card['character']} attacks {health_problem} with {player_card['action_dice']}...")
77
+ attack_score = random.randint(*attack_range)
78
+ defense_score = random.randint(*defense_range)
79
+ health_ferocity = random.randint(*attack_range)
80
+ health_resistance = random.randint(*defense_range)
81
+ if attack_score > health_resistance:
82
+ player_card["score"] += 1
83
+ score_emoji = random.choice(score_emojis)
84
+ player_card["score_emoji"] = player_card.get("score_emoji", "") + score_emoji
85
+ st.write(f"{player_card['sketch']} {player_card['character']} deals {attack_score - health_resistance} damage to {health_problem}! {score_emoji}")
86
+ player_card["health_tokens"] += 1
87
+ health_token_emoji = random.choice(health_token_emojis)
88
+ player_card["health_token_emoji"] = player_card.get("health_token_emoji", "") + health_token_emoji
89
+ #player_card["coin"] += 10
90
+
91
+ #player_card["coin"] += 10
92
+ coin_emoji = random.choice(coin_emojis)
93
+ player_card["coin_emojis"] = player_card.get("coin_emojis", "") + coin_emoji
94
+
95
+ coin_emoji = random.choice(coin_emojis)
96
+ player_card["coin_emoji"] = player_card.get("coin_emoji", "") + coin_emoji
97
+ else:
98
+ st.write(f"{player_card['sketch']} {player_card['character']} misses the attack!")
99
+ if health_ferocity > defense_score:
100
+ player_card["health_tokens"] -= 1
101
+ health_token_emoji = random.choice(health_token_emojis)
102
+ player_card["health_token_emoji"] = player_card.get("health_token_emoji", "") + health_token_emoji
103
+ st.write(f"{health_problem} deals {health_ferocity - defense_score} damage to {player_card['sketch']} {player_card['character']}! {health_token_emoji}")
104
+ else:
105
+ st.write(f"{health_problem} fails to attack!")
106
+
107
+
108
+ # Create a function to play multiple rounds of the game
109
+ def play_game(num_games):
110
+ # Initialize the game state
111
+ for player in player_cards:
112
+ player_cards[player]["health_tokens"] = 20
113
+ health_problem_scores = {problem: 0 for problem in health_problems}
114
+ for i in range(num_games):
115
+ # Randomly select a player and health problem
116
+ player = random.choice(list(player_cards.keys()))
117
+ health_problem = random.choice(health_problems)
118
+ # Play the round
119
+ play_round(player_cards[player], health_problem)
120
+ # Update the scores
121
+ health_problem_scores[health_problem] += 1
122
+ # Check for a player win
123
+ for player, attributes in player_cards.items():
124
+ if attributes["health_tokens"] <= 0:
125
+ st.write(f"{attributes['sketch']} {attributes['character']} has lost the game!")
126
+ else:
127
+ if attributes["score"] >= num_games / 2:
128
+ st.write(f"{attributes['sketch']} {attributes['character']} has won the game!")
129
+ # Add a trophy emoji to the player card on the sidebar
130
+ if attributes["trophy"] == "":
131
+ attributes["trophy"] = "๐Ÿ†"
132
+ if st.session_state.get(player + "_win", False):
133
+ if attributes["trophy"] == "๐Ÿ†":
134
+ attributes["trophy"] = random.choice(["๐Ÿฅ‡", "๐Ÿฅˆ", "๐Ÿฅ‰"])
135
+ st.sidebar.write(f"{attributes['sketch']} {attributes['character']} {attributes['trophy']}")
136
+ # Save the game state to a CSV file
137
+ with open("game_state.csv", "a", newline="") as f:
138
+ writer = csv.writer(f)
139
+ if os.stat("game_state.csv").st_size == 0:
140
+ writer.writerow(["Player", "Sketch", "Character", "Player Board", "Action Dice", "Health Tokens", "Coin", "Battle Tokens", "Score", "Trophy"])
141
+ for player, attributes in player_cards.items():
142
+ row = [player, attributes["sketch"], attributes["character"], attributes["player_board"], attributes["action_dice"], attributes["health_tokens"], attributes["coin"], attributes["battle_tokens"], attributes["score"], attributes["trophy"]]
143
+ writer.writerow(row)
144
+ for problem in health_problems:
145
+ row = [problem, health_problem_scores[problem]]
146
+ writer.writerow(row)
147
+ # Display the game results
148
+ st.write("# Game Results")
149
+ for player, attributes in player_cards.items():
150
+ st.write(f"{attributes['sketch']} {attributes['character']}: {attributes['score']} successful attacks, {attributes['health_tokens']} health tokens, {attributes['coin']} coins")
151
+ for problem, score in health_problem_scores.items():
152
+ st.write(f"{problem}: {score} defeats")
153
+ # Display a button to download the game state CSV file
154
+ if os.path.exists("game_state.csv"):
155
+ st.write("# Download Game State")
156
+ files = [f for f in os.listdir(".") if os.path.isfile(f) and f.endswith(".csv")]
157
+ if "game_state.csv" in files:
158
+ files.remove("game_state.csv")
159
+ if len(files) > 0:
160
+ file_to_delete = st.selectbox("Select a file to delete", files)
161
+ if st.button("Delete File"):
162
+ os.remove(file_to_delete)
163
+ if st.button("Download Game State"):
164
+ with open("game_state.csv", "r") as f:
165
+ csv_data = f.read()
166
+ st.download_button("game_state.csv", csv_data, file_name="game_state.csv", mime="text/csv")
167
+ st.write("*Note: Downloaded files are saved in your browser's default download location*")
168
+
169
+ # Define the Streamlit app
170
+ def app():
171
+ st.set_page_config(page_title="Health Care Game", page_icon="๐Ÿฅ", layout="wide")
172
+ st.title("Health Care Game")
173
+ st.sidebar.write("# Game Settings")
174
+ num_games = st.sidebar.slider("Number of games to play", 1, 100, 10)
175
+ st.sidebar.write("# Player Cards")
176
+ for player, attributes in player_cards.items():
177
+ st.sidebar.write(f"## {player}")
178
+ st.sidebar.write(f"Sketch: {attributes['sketch']}")
179
+ st.sidebar.write(f"Character: {attributes['character']}")
180
+ st.sidebar.write(f"Player Board: {attributes['player_board']}")
181
+ st.sidebar.write(f"Action Dice: {attributes['action_dice']}")
182
+ st.sidebar.write(f"Health Tokens: {attributes['health_tokens']}")
183
+ st.sidebar.write(f"Coin: {attributes['coin']}")
184
+ st.sidebar.write(f"Battle Tokens: {attributes['battle_tokens']}")
185
+ st.sidebar.write(f"Score: {attributes['score']}")
186
+ # Display a button to start the game
187
+ if st.sidebar.button("Start Game"):
188
+ # Play the game
189
+ play_game(num_games)
190
+
191
+
192
+ def showPressRelease():
193
+ st.markdown("""
194
+
195
+ title: ๐Ÿค–๐Ÿง AI-RPG-Self-Play-RLML-Health-Battler-Game๐Ÿ†๐ŸŽ๐ŸŽฎ
196
+ emoji: ๐Ÿ‹๏ธโ€โ™€๏ธ๐Ÿ’ช๐Ÿฅ
197
+ # AI RPG Self-Play RL ML Health Battler Game Press Release
198
+ ## Introduction
199
+ ๐ŸŽ‰๐ŸŽฎ๐Ÿค– Attention all gamers and health enthusiasts! The ultimate weapon to battle health problems has arrived - the AI RPG Self-Play RL ML Health Battler Game! ๐Ÿค–๐ŸŽฎ๐ŸŽ‰
200
+ ## Gamified Health Battles
201
+ - ๐Ÿ‹๏ธโ€โ™€๏ธ๐Ÿ’ช๐Ÿฅ Sick of boring workouts and mundane health routines? Get ready to take on health problems like never before with our gamified approach. ๐ŸŽ‰๐Ÿ•น๏ธ
202
+ ## Advanced AI Technology
203
+ - ๐Ÿค–๐Ÿง ๐Ÿ”ฅ The AI technology behind our game is so advanced, you'll think you're battling a real-life disease! Let the personalized gameplay experience adapt to your style and keep you engaged for hours on end. ๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ”ฌ
204
+ ## Healthy Competition
205
+ - ๐Ÿ†๐ŸŽ๐ŸŽฎ Ready for some healthy competition? Compete against friends and other players around the world, earning rewards and achievements with our self-play reinforcement learning algorithms. ๐ŸŒŽ๐Ÿ†
206
+ ## Availability
207
+ - ๐Ÿ‘จโ€๐Ÿ’ป๐Ÿ“ฒ The AI RPG Self-Play RL ML Health Battler Game is now available for public open source use on all platforms, including iOS and Android devices, via the world's largest ML platform Huggingface! Download now and start fighting for your health. ๐Ÿ“ฒ๐Ÿ’ฅ
208
+ ## Conclusion
209
+ - Don't let health problems get the best of you - join the fight with our AI RPG Self-Play RL ML Health Battler Game! ๐ŸŽฎ๐Ÿ’ช๐Ÿฉบ
210
+
211
+ """)
212
+
213
+ # Define the Streamlit app
214
+ def app():
215
+ st.set_page_config(page_title="Health Care Game", page_icon="๐Ÿฅ", layout="wide")
216
+ st.title("Health Care Game")
217
+ st.sidebar.write("# Game Settings")
218
+ num_games = st.sidebar.slider("Number of games to play", 1, 100, 10)
219
+ st.sidebar.write("# Player Cards")
220
+ for player, attributes in player_cards.items():
221
+ st.sidebar.write(f"## {player}")
222
+ st.sidebar.write(f"Sketch: {attributes['sketch']}")
223
+ st.sidebar.write(f"Character: {attributes['character']}")
224
+ st.sidebar.write(f"Player Board: {attributes['player_board']}")
225
+ st.sidebar.write(f"Action Dice: {attributes['action_dice']}")
226
+ st.sidebar.write(f"Health Tokens: {attributes['health_tokens']}")
227
+ st.sidebar.write(f"Coin: {attributes['coin']}")
228
+ st.sidebar.write(f"Battle Tokens: {attributes['battle_tokens']}")
229
+ st.sidebar.write("# Health Problems")
230
+ for problem in health_problems:
231
+ st.sidebar.write(f"- {problem}")
232
+ # Start the game when the user clicks the "Play Game" button
233
+ if st.button("Play Game"):
234
+ play_game(num_games)
235
+ showPressRelease()
236
+
237
+
238
+
239
+
240
+ if __name__ == "__main__":
241
+ app()
242
+