Spaces:
Build error
Build error
import streamlit as st | |
import random | |
import csv | |
import os | |
# Define the player card attributes | |
player_cards = { | |
"Player 1": { | |
"sketch": "👩", | |
"character": "Nurse", | |
"player_board": "🏥", | |
"action_dice": "🎲", | |
"health_tokens": "❤️", | |
"coin": "💰", | |
"battle_tokens": "⚔️", | |
"score": 0, | |
"trophy": "" | |
}, | |
"Player 2": { | |
"sketch": "👨", | |
"character": "Doctor", | |
"player_board": "🏥", | |
"action_dice": "🎲", | |
"health_tokens": "❤️", | |
"coin": "💰", | |
"battle_tokens": "⚔️", | |
"score": 0, | |
"trophy": "" | |
} | |
} | |
# Define the health problems | |
health_problems = ["Flu", "COVID-19", "Diabetes", "Heart Disease", "Cancer"] | |
# Define the game rules | |
attack_range = (1, 20) | |
defense_range = (1, 10) | |
# Define the score, health tokens, and coin emoji sets | |
score_emojis = ["🔥", "💥", "⚡️", "👊", "💪", "🏋️", "👑", "🎉", "🎊", "🎖️", "🏅", "🥇", "🥈", "🥉"] | |
health_token_emojis = ["❤️", "💖", "💘", "💝", "💞", "💓", "💗", "💕", "💟", "❣️", "🩸", "🧡", "💛", "💚", "💙", "💜"] | |
coin_emojis = ["💰", "💸", "💳", "🤑", "💎", "💷", "💵", "💲", "🏦", "💹", "📈", "📉", "💹", "🤑", "💰", "💵"] | |
# Create a function to play a single round of the game | |
def play_round(player_card, health_problem): | |
st.write(f"{player_card['sketch']} {player_card['character']} attacks {health_problem} with {player_card['action_dice']}...") | |
attack_score = random.randint(*attack_range) | |
defense_score = random.randint(*defense_range) | |
health_ferocity = random.randint(*attack_range) | |
health_resistance = random.randint(*defense_range) | |
if attack_score > health_resistance: | |
player_card["score"] += 1 | |
score_emoji = random.choice(score_emojis) | |
player_card["score_emoji"] = player_card.get("score_emoji", "") + score_emoji | |
st.write(f"{player_card['sketch']} {player_card['character']} deals {attack_score - health_resistance} damage to {health_problem}! {score_emoji}") | |
player_card["health_tokens"] += 1 | |
health_token_emoji = random.choice(health_token_emojis) | |
player_card["health_token_emoji"] = player_card.get("health_token_emoji", "") + health_token_emoji | |
#player_card["coin"] += 10 | |
#player_card["coin"] += 10 | |
coin_emoji = random.choice(coin_emojis) | |
player_card["coin_emojis"] = player_card.get("coin_emojis", "") + coin_emoji | |
coin_emoji = random.choice(coin_emojis) | |
player_card["coin_emoji"] = player_card.get("coin_emoji", "") + coin_emoji | |
else: | |
st.write(f"{player_card['sketch']} {player_card['character']} misses the attack!") | |
if health_ferocity > defense_score: | |
player_card["health_tokens"] -= 1 | |
health_token_emoji = random.choice(health_token_emojis) | |
player_card["health_token_emoji"] = player_card.get("health_token_emoji", "") + health_token_emoji | |
st.write(f"{health_problem} deals {health_ferocity - defense_score} damage to {player_card['sketch']} {player_card['character']}! {health_token_emoji}") | |
else: | |
st.write(f"{health_problem} fails to attack!") | |
# Create a function to play multiple rounds of the game | |
def play_game(num_games): | |
# Initialize the game state | |
for player in player_cards: | |
player_cards[player]["health_tokens"] = 20 | |
health_problem_scores = {problem: 0 for problem in health_problems} | |
for i in range(num_games): | |
# Randomly select a player and health problem | |
player = random.choice(list(player_cards.keys())) | |
health_problem = random.choice(health_problems) | |
# Play the round | |
play_round(player_cards[player], health_problem) | |
# Update the scores | |
health_problem_scores[health_problem] += 1 | |
# Check for a player win | |
for player, attributes in player_cards.items(): | |
if attributes["health_tokens"] <= 0: | |
st.write(f"{attributes['sketch']} {attributes['character']} has lost the game!") | |
else: | |
if attributes["score"] >= num_games / 2: | |
st.write(f"{attributes['sketch']} {attributes['character']} has won the game!") | |
# Add a trophy emoji to the player card on the sidebar | |
if attributes["trophy"] == "": | |
attributes["trophy"] = "🏆" | |
if st.session_state.get(player + "_win", False): | |
if attributes["trophy"] == "🏆": | |
attributes["trophy"] = random.choice(["🥇", "🥈", "🥉"]) | |
st.sidebar.write(f"{attributes['sketch']} {attributes['character']} {attributes['trophy']}") | |
# Save the game state to a CSV file | |
with open("game_state.csv", "a", newline="") as f: | |
writer = csv.writer(f) | |
if os.stat("game_state.csv").st_size == 0: | |
writer.writerow(["Player", "Sketch", "Character", "Player Board", "Action Dice", "Health Tokens", "Coin", "Battle Tokens", "Score", "Trophy"]) | |
for player, attributes in player_cards.items(): | |
row = [player, attributes["sketch"], attributes["character"], attributes["player_board"], attributes["action_dice"], attributes["health_tokens"], attributes["coin"], attributes["battle_tokens"], attributes["score"], attributes["trophy"]] | |
writer.writerow(row) | |
for problem in health_problems: | |
row = [problem, health_problem_scores[problem]] | |
writer.writerow(row) | |
# Display the game results | |
st.write("# Game Results") | |
for player, attributes in player_cards.items(): | |
st.write(f"{attributes['sketch']} {attributes['character']}: {attributes['score']} successful attacks, {attributes['health_tokens']} health tokens, {attributes['coin']} coins") | |
for problem, score in health_problem_scores.items(): | |
st.write(f"{problem}: {score} defeats") | |
# Display a button to download the game state CSV file | |
if os.path.exists("game_state.csv"): | |
st.write("# Download Game State") | |
files = [f for f in os.listdir(".") if os.path.isfile(f) and f.endswith(".csv")] | |
if "game_state.csv" in files: | |
files.remove("game_state.csv") | |
if len(files) > 0: | |
file_to_delete = st.selectbox("Select a file to delete", files) | |
if st.button("Delete File"): | |
os.remove(file_to_delete) | |
if st.button("Download Game State"): | |
with open("game_state.csv", "r") as f: | |
csv_data = f.read() | |
st.download_button("game_state.csv", csv_data, file_name="game_state.csv", mime="text/csv") | |
st.write("*Note: Downloaded files are saved in your browser's default download location*") | |
# Define the Streamlit app | |
def app(): | |
st.set_page_config(page_title="Health Care Game", page_icon="🏥", layout="wide") | |
st.title("Health Care Game") | |
st.sidebar.write("# Game Settings") | |
num_games = st.sidebar.slider("Number of games to play", 1, 100, 10) | |
st.sidebar.write("# Player Cards") | |
for player, attributes in player_cards.items(): | |
st.sidebar.write(f"## {player}") | |
st.sidebar.write(f"Sketch: {attributes['sketch']}") | |
st.sidebar.write(f"Character: {attributes['character']}") | |
st.sidebar.write(f"Player Board: {attributes['player_board']}") | |
st.sidebar.write(f"Action Dice: {attributes['action_dice']}") | |
st.sidebar.write(f"Health Tokens: {attributes['health_tokens']}") | |
st.sidebar.write(f"Coin: {attributes['coin']}") | |
st.sidebar.write(f"Battle Tokens: {attributes['battle_tokens']}") | |
st.sidebar.write(f"Score: {attributes['score']}") | |
# Display a button to start the game | |
if st.sidebar.button("Start Game"): | |
# Play the game | |
play_game(num_games) | |
def showPressRelease(): | |
st.markdown(""" | |
title: 🤖🧠AI-RPG-Self-Play-RLML-Health-Battler-Game🏆🎁🎮 | |
emoji: 🏋️♀️💪🏥 | |
# AI RPG Self-Play RL ML Health Battler Game Press Release | |
## Introduction | |
🎉🎮🤖 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! 🤖🎮🎉 | |
## Gamified Health Battles | |
- 🏋️♀️💪🏥 Sick of boring workouts and mundane health routines? Get ready to take on health problems like never before with our gamified approach. 🎉🕹️ | |
## Advanced AI Technology | |
- 🤖🧠🔥 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. 💻👨🔬 | |
## Healthy Competition | |
- 🏆🎁🎮 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. 🌎🏆 | |
## Availability | |
- 👨💻📲 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. 📲💥 | |
## Conclusion | |
- Don't let health problems get the best of you - join the fight with our AI RPG Self-Play RL ML Health Battler Game! 🎮💪🩺 | |
Links to More About Health Games! | |
1. Health Game Terminology: https://en.wikipedia.org/wiki/Health_(game_terminology) | |
2. Games for Health: https://en.wikipedia.org/wiki/Games_for_Health | |
3. Wii Fit: https://en.wikipedia.org/wiki/Wii_Fit#Development | |
4. Cross Fit Games: https://en.wikipedia.org/wiki/CrossFit_Games | |
5. Digital Media and Mental Health: https://en.wikipedia.org/wiki/Digital_media_use_and_mental_health | |
6. Use of Technology for Mental Health: https://en.wikipedia.org/wiki/Use_of_technology_in_treatment_of_mental_disorders | |
""") | |
# Define the Streamlit app | |
def app(): | |
st.set_page_config(page_title="Health Care Game", page_icon="🏥", layout="wide") | |
st.title("Health Care Game") | |
st.sidebar.write("# Game Settings") | |
num_games = st.sidebar.slider("Number of games to play", 1, 100, 10) | |
st.sidebar.write("# Player Cards") | |
for player, attributes in player_cards.items(): | |
st.sidebar.write(f"## {player}") | |
st.sidebar.write(f"Sketch: {attributes['sketch']}") | |
st.sidebar.write(f"Character: {attributes['character']}") | |
st.sidebar.write(f"Player Board: {attributes['player_board']}") | |
st.sidebar.write(f"Action Dice: {attributes['action_dice']}") | |
st.sidebar.write(f"Health Tokens: {attributes['health_tokens']}") | |
st.sidebar.write(f"Coin: {attributes['coin']}") | |
st.sidebar.write(f"Battle Tokens: {attributes['battle_tokens']}") | |
st.sidebar.write("# Health Problems") | |
for problem in health_problems: | |
st.sidebar.write(f"- {problem}") | |
# Start the game when the user clicks the "Play Game" button | |
if st.button("Play Game"): | |
play_game(num_games) | |
showPressRelease() | |
if __name__ == "__main__": | |
app() | |