Closed duck57 closed 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.
find_a_fit()
in generate.py only cares aboutWordSearch.directions
and never checks if the word is secret or limits itself to usingWordSeach.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 havingword: str
toword: Word
and switch which set of valid directions to use depending ifword.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 tofind_a_fit
. Switching the set of valid directions would be handled infill_words
and passed throughtry_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).