Create word search algorithm#8906
Conversation
|
@tianyizheng02 Pinging for review |
| # Board matrix holding each letter | ||
| self.board: list[list[str | None]] = [[None] * width for _ in range(height)] | ||
|
|
||
| def insert_north(self, word: str, rows: list[int], cols: list[int]) -> None: |
There was a problem hiding this comment.
It'd help to have the block comment explain what rows and cols are for
| shuffle(cols) | ||
|
|
||
| # Insert the word via the direction | ||
| choice(directions)(word, rows, cols) |
There was a problem hiding this comment.
Isn't it possible for the insert_... functions to fail to insert a word? Can we ensure that the word will actually be inserted?
There was a problem hiding this comment.
You are correct, the function will fail if there is not enough space on the board to insert the word. I will refactor the logic of the insertions to return whether or not the insertion was successful or not, and then raise and error if the insertion was unsuccessful
| character = letter | ||
| # Empty char, so add a fake char | ||
| elif add_fake_chars: | ||
| character = chr(randint(97, 122)) |
There was a problem hiding this comment.
Can we have input words restricted to just lowercase English letters? If you're just padding out the word search with random English lowercase letters and the user chooses words that use other characters (uppercase English letters, etc) then the inserted words would stand out.
There was a problem hiding this comment.
We can limit to only lowercase english letters 👍
Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
|
@CaedenPH pre-commit and build are failing due to incorrect function names, please fix: |
Describe your change:
Create a word search algorithm
Checklist: