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 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:') columns = st.columns(7) for idx, (col, letter) in enumerate(zip(columns, player_letters)): with col: # Use both letter and index to create a unique key button_key = f"player_{letter}_{idx}" if st.button(f"{letter_emojis[letter]} {letters_scores[letter]}", key=button_key): player_word.append(letter) player_score += letters_scores[letter] # Mark the button as used by adding to session state st.session_state[button_key] = True # 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_state['finish'] = True