other.word_search¶
Creates a random wordsearch with eight different directions that are best described as compass locations.
@ https://en.wikipedia.org/wiki/Word_search
Attributes¶
Classes¶
Functions¶
|
Graphically displays the word search in the terminal. |
Module Contents¶
- class other.word_search.WordSearch(words: list[str], width: int, height: int)¶
>>> ws = WordSearch(WORDS, WIDTH, HEIGHT) >>> ws.board [[None, ..., None], ..., [None, ..., None]] >>> ws.generate_board()
- generate_board() None ¶
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)) True
- insert_east(word: str, rows: list[int], cols: list[int]) None ¶
>>> ws = WordSearch(WORDS, 3, 3) >>> ws.insert_east("cat", [1], [0]) >>> ws.board [[None, None, None], ['c', 'a', 't'], [None, None, None]] >>> ws.insert_east("at", [1, 0], [2, 1, 0]) >>> ws.board [[None, 'a', 't'], ['c', 'a', 't'], [None, None, None]]
- insert_north(word: str, rows: list[int], cols: list[int]) None ¶
>>> ws = WordSearch(WORDS, 3, 3) >>> ws.insert_north("cat", [2], [2]) >>> ws.board [[None, None, 't'], [None, None, 'a'], [None, None, 'c']] >>> ws.insert_north("at", [0, 1, 2], [2, 1]) >>> ws.board [[None, 't', 't'], [None, 'a', 'a'], [None, None, 'c']]
- insert_northeast(word: str, rows: list[int], cols: list[int]) None ¶
>>> ws = WordSearch(WORDS, 3, 3) >>> ws.insert_northeast("cat", [2], [0]) >>> ws.board [[None, None, 't'], [None, 'a', None], ['c', None, None]] >>> ws.insert_northeast("at", [0, 1], [2, 1, 0]) >>> ws.board [[None, 't', 't'], ['a', 'a', None], ['c', None, None]]
- insert_northwest(word: str, rows: list[int], cols: list[int]) None ¶
>>> ws = WordSearch(WORDS, 3, 3) >>> ws.insert_northwest("cat", [2], [2]) >>> ws.board [['t', None, None], [None, 'a', None], [None, None, 'c']] >>> ws.insert_northwest("at", [1, 2], [0, 1]) >>> ws.board [['t', None, None], ['t', 'a', None], [None, 'a', 'c']]
- insert_south(word: str, rows: list[int], cols: list[int]) None ¶
>>> ws = WordSearch(WORDS, 3, 3) >>> ws.insert_south("cat", [0], [0]) >>> ws.board [['c', None, None], ['a', None, None], ['t', None, None]] >>> ws.insert_south("at", [2, 1, 0], [0, 1, 2]) >>> ws.board [['c', None, None], ['a', 'a', None], ['t', 't', None]]
- insert_southeast(word: str, rows: list[int], cols: list[int]) None ¶
>>> ws = WordSearch(WORDS, 3, 3) >>> ws.insert_southeast("cat", [0], [0]) >>> ws.board [['c', None, None], [None, 'a', None], [None, None, 't']] >>> ws.insert_southeast("at", [1, 0], [2, 1, 0]) >>> ws.board [['c', None, None], ['a', 'a', None], [None, 't', 't']]
- insert_southwest(word: str, rows: list[int], cols: list[int]) None ¶
>>> ws = WordSearch(WORDS, 3, 3) >>> ws.insert_southwest("cat", [0], [2]) >>> ws.board [[None, None, 'c'], [None, 'a', None], ['t', None, None]] >>> ws.insert_southwest("at", [1, 2], [2, 1, 0]) >>> ws.board [[None, None, 'c'], [None, 'a', 'a'], ['t', 't', None]]
- insert_west(word: str, rows: list[int], cols: list[int]) None ¶
>>> ws = WordSearch(WORDS, 3, 3) >>> ws.insert_west("cat", [1], [2]) >>> ws.board [[None, None, None], ['t', 'a', 'c'], [None, None, None]] >>> ws.insert_west("at", [1, 0], [1, 2, 0]) >>> ws.board [['t', 'a', None], ['t', 'a', 'c'], [None, None, None]]
- board: list[list[str | None]]¶
- height¶
- width¶
- words¶
- other.word_search.visualise_word_search(board: list[list[str | None]] | None = None, *, add_fake_chars: bool = True) None ¶
Graphically displays the word search in the terminal.
>>> ws = WordSearch(WORDS, 5, 5) >>> ws.insert_north("cat", [4], [4]) >>> visualise_word_search( ... ws.board, add_fake_chars=False) # # # # # # # # # # # # # # t # # # # a # # # # c >>> ws.insert_northeast("snake", [4], [4, 3, 2, 1, 0]) >>> visualise_word_search( ... ws.board, add_fake_chars=False) # # # # e # # # k # # # a # t # n # # a s # # # c
- other.word_search.HEIGHT = 10¶
- other.word_search.WIDTH = 10¶
- other.word_search.WORDS = ['cat', 'dog', 'snake', 'fish']¶