File size: 2,524 Bytes
1591c02
 
 
 
89f1b7a
 
 
1591c02
89f1b7a
 
a9476d9
 
 
 
 
 
 
 
 
1591c02
89f1b7a
 
 
 
 
 
 
 
 
1591c02
89f1b7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
973e097
 
 
 
 
 
 
 
 
 
 
 
 
a800fe4
 
973e097
a800fe4
 
973e097
 
 
 
1591c02
89f1b7a
973e097
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
import streamlit as st
import random
import string

board_size = 15
words = []
board = [[' ' for _ in range(board_size)] for _ in range(board_size)]

def load_word_list():
    global words
    try:
        with open("word_list.txt", "r") as f:
            words = f.read().split("\n")
    except FileNotFoundError:
        pass
    st.text_area("Enter a list of words (one per line)", "\n".join(words))
    st.sidebar.subheader("Word List:")
    for i, word in enumerate(words):
        st.sidebar.write(f"{i+1}. {word}")

def save_word_list():
    global words
    with open("word_list.txt", "w") as f:
        f.write("\n".join(words))
    st.write("Word list saved successfully!")

def generate_board():
    global board, words
    board = [[' ' for _ in range(board_size)] for _ in range(board_size)]
    for word in words:
        word = word.upper()
        row, col = random.randint(0, board_size - 1), random.randint(0, board_size - 1)
        direction = random.choice(['horizontal', 'vertical', 'diagonal'])
        if direction == 'horizontal' and col + len(word) <= board_size:
            for i, letter in enumerate(word):
                board[row][col+i] = letter
        elif direction == 'vertical' and row + len(word) <= board_size:
            for i, letter in enumerate(word):
                board[row+i][col] = letter
        elif direction == 'diagonal' and row + len(word) <= board_size and col + len(word) <= board_size:
            for i, letter in enumerate(word):
                board[row+i][col+i] = letter
    for i in range(board_size):
        for j in range(board_size):
            if board[i][j] == ' ':
                board[i][j] = random.choice(string.ascii_uppercase)

buttons = {
    "Load Word List": load_word_list,
    "Save Word List": save_word_list,
    "Generate Board": generate_board
}

for button_label, button_func in buttons.items():
    if st.sidebar.button(button_label):
        words = st.text_area("Enter a list of words (one per line)", "\n".join(words)).split("\n")
        button_func()
        st.sidebar.subheader("Word List:")
        for i, word in enumerate(words):
            st.sidebar.write(f"{i+1}. {word}")

words = st.text_area("Enter a list of words (one per line)", "\n".join(words))
if st.button("Save Word List", key="save_word_list_btn"):
    words = words.split("\n")
    save_word_list()

st.sidebar.subheader("Word List:")
for i, word in enumerate(words):
    st.sidebar.write(f"{i+1}. {word}")

st.write("Word Search Board:")
st.table(board)