other.word_search ================= .. py:module:: other.word_search .. autoapi-nested-parse:: Creates a random wordsearch with eight different directions that are best described as compass locations. @ https://en.wikipedia.org/wiki/Word_search Attributes ---------- .. autoapisummary:: other.word_search.HEIGHT other.word_search.WIDTH other.word_search.WORDS Classes ------- .. autoapisummary:: other.word_search.WordSearch Functions --------- .. autoapisummary:: other.word_search.visualise_word_search Module Contents --------------- .. py:class:: WordSearch(words: list[str], width: int, height: int) >>> ws = WordSearch(WORDS, WIDTH, HEIGHT) >>> ws.board # doctest: +ELLIPSIS [[None, ..., None], ..., [None, ..., None]] >>> ws.generate_board() .. py:method:: 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 .. py:method:: insert_east(word: str, rows: list[int], cols: list[int]) -> None >>> ws = WordSearch(WORDS, 3, 3) >>> ws.insert_east("cat", [1], [0]) >>> ws.board # doctest: +NORMALIZE_WHITESPACE [[None, None, None], ['c', 'a', 't'], [None, None, None]] >>> ws.insert_east("at", [1, 0], [2, 1, 0]) >>> ws.board # doctest: +NORMALIZE_WHITESPACE [[None, 'a', 't'], ['c', 'a', 't'], [None, None, None]] .. py:method:: insert_north(word: str, rows: list[int], cols: list[int]) -> None >>> ws = WordSearch(WORDS, 3, 3) >>> ws.insert_north("cat", [2], [2]) >>> ws.board # doctest: +NORMALIZE_WHITESPACE [[None, None, 't'], [None, None, 'a'], [None, None, 'c']] >>> ws.insert_north("at", [0, 1, 2], [2, 1]) >>> ws.board # doctest: +NORMALIZE_WHITESPACE [[None, 't', 't'], [None, 'a', 'a'], [None, None, 'c']] .. py:method:: insert_northeast(word: str, rows: list[int], cols: list[int]) -> None >>> ws = WordSearch(WORDS, 3, 3) >>> ws.insert_northeast("cat", [2], [0]) >>> ws.board # doctest: +NORMALIZE_WHITESPACE [[None, None, 't'], [None, 'a', None], ['c', None, None]] >>> ws.insert_northeast("at", [0, 1], [2, 1, 0]) >>> ws.board # doctest: +NORMALIZE_WHITESPACE [[None, 't', 't'], ['a', 'a', None], ['c', None, None]] .. py:method:: insert_northwest(word: str, rows: list[int], cols: list[int]) -> None >>> ws = WordSearch(WORDS, 3, 3) >>> ws.insert_northwest("cat", [2], [2]) >>> ws.board # doctest: +NORMALIZE_WHITESPACE [['t', None, None], [None, 'a', None], [None, None, 'c']] >>> ws.insert_northwest("at", [1, 2], [0, 1]) >>> ws.board # doctest: +NORMALIZE_WHITESPACE [['t', None, None], ['t', 'a', None], [None, 'a', 'c']] .. py:method:: insert_south(word: str, rows: list[int], cols: list[int]) -> None >>> ws = WordSearch(WORDS, 3, 3) >>> ws.insert_south("cat", [0], [0]) >>> ws.board # doctest: +NORMALIZE_WHITESPACE [['c', None, None], ['a', None, None], ['t', None, None]] >>> ws.insert_south("at", [2, 1, 0], [0, 1, 2]) >>> ws.board # doctest: +NORMALIZE_WHITESPACE [['c', None, None], ['a', 'a', None], ['t', 't', None]] .. py:method:: insert_southeast(word: str, rows: list[int], cols: list[int]) -> None >>> ws = WordSearch(WORDS, 3, 3) >>> ws.insert_southeast("cat", [0], [0]) >>> ws.board # doctest: +NORMALIZE_WHITESPACE [['c', None, None], [None, 'a', None], [None, None, 't']] >>> ws.insert_southeast("at", [1, 0], [2, 1, 0]) >>> ws.board # doctest: +NORMALIZE_WHITESPACE [['c', None, None], ['a', 'a', None], [None, 't', 't']] .. py:method:: insert_southwest(word: str, rows: list[int], cols: list[int]) -> None >>> ws = WordSearch(WORDS, 3, 3) >>> ws.insert_southwest("cat", [0], [2]) >>> ws.board # doctest: +NORMALIZE_WHITESPACE [[None, None, 'c'], [None, 'a', None], ['t', None, None]] >>> ws.insert_southwest("at", [1, 2], [2, 1, 0]) >>> ws.board # doctest: +NORMALIZE_WHITESPACE [[None, None, 'c'], [None, 'a', 'a'], ['t', 't', None]] .. py:method:: insert_west(word: str, rows: list[int], cols: list[int]) -> None >>> ws = WordSearch(WORDS, 3, 3) >>> ws.insert_west("cat", [1], [2]) >>> ws.board # doctest: +NORMALIZE_WHITESPACE [[None, None, None], ['t', 'a', 'c'], [None, None, None]] >>> ws.insert_west("at", [1, 0], [1, 2, 0]) >>> ws.board # doctest: +NORMALIZE_WHITESPACE [['t', 'a', None], ['t', 'a', 'c'], [None, None, None]] .. py:attribute:: board :type: list[list[str | None]] .. py:attribute:: height .. py:attribute:: width .. py:attribute:: words .. py:function:: 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) # doctest: +NORMALIZE_WHITESPACE # # # # # # # # # # # # # # t # # # # a # # # # c >>> ws.insert_northeast("snake", [4], [4, 3, 2, 1, 0]) >>> visualise_word_search( ... ws.board, add_fake_chars=False) # doctest: +NORMALIZE_WHITESPACE # # # # e # # # k # # # a # t # n # # a s # # # c .. py:data:: HEIGHT :value: 10 .. py:data:: WIDTH :value: 10 .. py:data:: WORDS :value: ['cat', 'dog', 'snake', 'fish']