The problem I am having is whenever I am trying to find a spot and place a word in my grid of letters 11x11, I just get an infinite loop of "False" and the word or words don't get placed in the grid.
I am trying to make a word search "game", and by that I mean make something that looks like a word search using opencv, make a .png and then print out the image, etc.
I am basically looking for a way to have words be placed in a grid of letters, changing an existing letter in the grid to a letter in the word that's in the list of words. I want to try and achieve having something where the letter "t" in "python" can be also used for the letter "t" in "html".
I would try chatGPT but my past experiences with the thing has always been negative and it never spits out functioning code.
I have also tried the following: - (and what I want to work with more)
I have tried a function from (Building a wordsearch generator in python) and that kinda worked...unfortunately some of the words in my list had a letter overwrite another letter in a different word.
For example, In this image:
The "N" in "PYTHON" and the "M" in BOOKWORM was overwritten by the "M" & "H" in HTML. And I can't even find "Bananas" So I assume it was overwritten or left out.
This is the function that resulted in the above/attached image:
def place_word(grid, word):
width = len(grid)
height = len(grid[0])
word = word.upper()
word = random.choice([word, word[::-1]])
direction = random.choice([[1,0], [0,1], [1,1]])
print(f'Placing {word} in direction {direction}...')
xstart = width if direction[0] == 0 else width - len(word) - 1
ystart = height if direction[1] == 0 else height - len(word) - 1
x = random.randrange(0, xstart)
y = random.randrange(0, ystart)
for c in range(len(word)):
grid[x + direction[0]*c][y + direction[1]*c] = word[c]
return grid
I want to work with this function more but could use some help ironing out the obvious kinks... (having all words be present and findable, having words intersect but not overwrite letters in other words unless they are the same letter.)
Any help would be very appreciated.
