Generates a board with a random direction for each word. >>> wt = WordSearch(WORDS, WIDTH, HEIGHT) >>> wt.generate_board() >>> len(list(filter(lambda word: word is not None, sum(wt.board, start=[]))) ... ) == sum(map(lambda word: len(word), WORDS)) T
(self)
| 314 | return |
| 315 | |
| 316 | def generate_board(self) -> None: |
| 317 | """ |
| 318 | Generates a board with a random direction for each word. |
| 319 | |
| 320 | >>> wt = WordSearch(WORDS, WIDTH, HEIGHT) |
| 321 | >>> wt.generate_board() |
| 322 | >>> len(list(filter(lambda word: word is not None, sum(wt.board, start=[]))) |
| 323 | ... ) == sum(map(lambda word: len(word), WORDS)) |
| 324 | True |
| 325 | """ |
| 326 | directions = ( |
| 327 | self.insert_north, |
| 328 | self.insert_northeast, |
| 329 | self.insert_east, |
| 330 | self.insert_southeast, |
| 331 | self.insert_south, |
| 332 | self.insert_southwest, |
| 333 | self.insert_west, |
| 334 | self.insert_northwest, |
| 335 | ) |
| 336 | for word in self.words: |
| 337 | # Shuffle the row order and column order that is used when brute forcing |
| 338 | # the insertion of the word |
| 339 | rows, cols = list(range(self.height)), list(range(self.width)) |
| 340 | shuffle(rows) |
| 341 | shuffle(cols) |
| 342 | |
| 343 | # Insert the word via the direction |
| 344 | choice(directions)(word, rows, cols) |
| 345 | |
| 346 | |
| 347 | def visualise_word_search( |
no outgoing calls
no test coverage detected