File size: 3,233 Bytes
29e0011
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4997f02
29e0011
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4997f02
29e0011
4997f02
29e0011
4997f02
 
 
29e0011
 
4997f02
 
29e0011
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4997f02
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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