awacke1 commited on
Commit
92ab0db
โ€ข
1 Parent(s): 6d08659

Create app.py

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