joshbduncan / word-search-generator

Make awesome Word Search puzzles!
MIT License
74 stars 24 forks source link

find_a_fit does not care about secret directions #42

Closed duck57 closed 1 year ago

duck57 commented 1 year ago

find_a_fit() in generate.py only cares about WordSearch.directions and never checks if the word is secret or limits itself to using WordSeach.secret_directions. I've typed a quick fix already.

The easiest fix (that I've already typed) is to change the type signature of find_a_fit from having word: str to word: Word and switch which set of valid directions to use depending if word.secret is True.

A more complex fix would be to leave word: str in the signature and add the list of valid directions as a param to find_a_fit. Switching the set of valid directions would be handled in fill_words and passed through try_to_fit_word. Doing it this way would allow API consumers to forcibly add a word in the direction of their choosing. However, the current generation flow does not provide an opportunity for an API client to inject words between word placement and filling the random letters.

Out-of-scope for this issue, but perhaps the WordSearch init could be modified to take a list of forced words to provide such a feature to API clients. Each forced_word would be tuple[str, set[Direction], bool]. The boolean in the tuple is whether or not the word is treated like a secret word (defaults to True).

joshbduncan commented 1 year ago

Good catch! I would say the first option makes the most sense. The other options would require a few additional changes to the API to keep up with any custom 'injected' directions that weren't already allowable within the WordSearch instance. Injected words with custom direction seems like a pretty extreme edge case.