awacke1's picture
Create app.py
29e0011 verified
raw
history blame
3.19 kB
import streamlit as st
import random
# Define letter scores and distribution
letters_scores = {
'A': 1, 'B': 3, 'C': 3, 'D': 2, 'E': 1, 'F': 4, 'G': 2, 'H': 4, 'I': 1,
'J': 8, 'K': 5, 'L': 1, 'M': 3, 'N': 1, 'O': 1, 'P': 3, 'Q': 10, 'R': 1,
'S': 1, 'T': 1, 'U': 1, 'V': 4, 'W': 4, 'X': 8, 'Y': 4, 'Z': 10
}
letters_distribution = {
'A': 9, 'B': 2, 'C': 2, 'D': 4, 'E': 12, 'F': 2, 'G': 3, 'H': 2, 'I': 9,
'J': 1, 'K': 1, 'L': 4, 'M': 2, 'N': 6, 'O': 8, 'P': 2, 'Q': 1, 'R': 6,
'S': 4, 'T': 6, 'U': 4, 'V': 2, 'W': 2, 'X': 1, 'Y': 2, 'Z': 1
}
flat_letters = [letter for letter, count in letters_distribution.items() for _ in range(count)]
# Emojis for letters (selected for better UTF-8 compatibility)
letter_emojis = {
'A': '๐Ÿ…ฐ๏ธ', 'B': '๐Ÿ…ฑ๏ธ', 'C': 'ยฉ๏ธ', 'D': '๐ŸŒ›', 'E': '๐Ÿ“ง', 'F': '๐ŸŽ', 'G': 'โ›ฝ', 'H': 'โ™“', 'I': 'โ„น๏ธ',
'J': '๐ŸŽท', 'K': '๐ŸŽ‹', 'L': '๐Ÿ›ด', 'M': 'โ“‚๏ธ', 'N': '๐ŸŽต', 'O': '๐Ÿ…พ๏ธ', 'P': '๐Ÿ…ฟ๏ธ', 'Q': '๐Ÿ”', 'R': 'ยฎ๏ธ',
'S': '๐Ÿ’ฒ', 'T': '๐ŸŒด', 'U': 'โ›Ž', 'V': 'โœ…', 'W': 'ใ€ฐ๏ธ', 'X': 'โŽ', 'Y': 'โœŒ๏ธ', 'Z': 'โšก'
}
# Streamlit app setup
st.title('Scrabble Simulator with Emojis')
# Player and computer scores and words
player_word = []
player_score = 0
computer_word = []
computer_score = 0
# Generate 7 random letters for player and computer
player_letters = random.sample(flat_letters, 7)
computer_letters = random.sample(flat_letters, 7)
# Display player's letters with emojis
st.subheader('Your Letters:')
col1, col2, col3, col4, col5, col6, col7 = st.columns(7)
columns = [col1, col2, col3, col4, col5, col6, col7]
for col, letter in zip(columns, player_letters):
with col:
if st.button(f"{letter_emojis[letter]} {letters_scores[letter]}", key=f"player_{letter}"):
player_word.append(letter)
player_score += letters_scores[letter]
st.session_state[f"player_{letter}"] = True # Disable the button
# Display player's current word and score
st.write(f"Your current word: {''.join(player_word)}")
st.write(f"Your current score: {player_score}")
# Computer's turn (simplified for this example)
computer_choice = random.choice(computer_letters)
computer_word.append(computer_choice)
computer_score += letters_scores[computer_choice]
st.subheader("Computer's Letters:")
st.write(f"๐Ÿค– Computer selected: {letter_emojis[computer_choice]} {letters_scores[computer_choice]}")
st.write(f"Computer's current word: {''.join(computer_word)}")
st.write(f"Computer's current score: {computer_score}")
# Display final scores and determine winner
if 'finish' in st.session_state and st.session_state['finish']:
st.write(f"Final word: {''.join(player_word)}")
st.write(f"Final score: {player_score}")
st.write("Game Over!")
st.write(f"Computer's final word: {''.join(computer_word)}")
st.write(f"Computer's final score: {computer_score}")
# Determine winner
if player_score > computer_score:
st.success("You win! ๐ŸŽ‰")
elif player_score < computer_score:
st.error("Computer wins! ๐Ÿ–ฅ๏ธ")
else:
st.warning("It's a tie! ๐Ÿค")
else:
if st.button("Finish Game"):
st.session_s