def test_one_blank(self): tiles = ['a', 'b', 'c', '?'] out = scrab.find_all_words(tiles, self.words) expected = ['bach', 'back', 'cabs', 'carb', 'crab', 'scab', \ 'aba', 'abo', 'abs', 'aby', 'ace', 'act', 'alb', 'arb', 'arc', 'baa', 'bad', 'bag', \ 'bah', 'bal', 'bam', 'ban', 'bap', 'bar', 'bas', 'bat', 'bay', 'boa', 'bra', 'cab', \ 'cad', 'cam', 'can', 'cap', 'car', 'cat', 'caw', 'cay', 'cob', 'cub', 'dab', 'fab', \ 'gab', 'jab', 'kab', 'lab', 'lac', 'mac', 'nab', 'oba', 'oca', 'pac', 'sab', 'sac', \ 'tab', 'vac', 'wab', \ 'aa', 'ab', 'ad', 'ae', 'ag', 'ah', 'ai', 'al', 'am', 'an', 'ar', 'as', 'at', 'aw', \ 'ax', 'ay', 'ba', 'be', 'bi', 'bo', 'by', 'da', 'fa', 'ha', 'ka', 'la', 'ma', 'na', \ 'pa', 'ta', 'ya', 'za'] np.testing.assert_array_equal(out, expected)
def test_two_blanks(self): tiles = ['x', 'z', 'z', '?', '?'] out = scrab.find_all_words(tiles, self.words) expected = ['buzz', 'fizz', 'fuzz', 'jazz', 'razz', \ 'adz', 'axe', 'azo', 'biz', 'box', 'cox', 'coz', 'dex', 'dux', 'fax', 'fez', 'fix', \ 'fiz', 'fox', 'gox', 'hex', 'kex', 'lax', 'lex', 'lez', 'lox', 'lux', 'max', 'mix', \ 'nix', 'oxo', 'oxy', 'pax', 'pix', 'pox', 'pyx', 'rax', 'rex', 'sax', 'sex', 'six', \ 'sox', 'tax', 'tux', 'vex', 'vox', 'wax', 'wiz', 'xis', 'zag', 'zap', 'zas', 'zax', \ 'zed', 'zee', 'zek', 'zen', 'zep', 'zig', 'zin', 'zip', 'zit', 'zoa', 'zoo', \ 'aa', 'ab', 'ad', 'ae', 'ag', 'ah', 'ai', 'al', 'am', 'an', 'ar', 'as', 'at', 'aw', \ 'ax', 'ay', 'ba', 'be', 'bi', 'bo', 'by', 'da', 'de', 'di', 'do', 'ed', 'ef', 'eh', \ 'el', 'em', 'en', 'er', 'es', 'et', 'ex', 'fa', 'fe', 'fi', 'gi', 'go', 'ha', 'he', \ 'hi', 'hm', 'ho', 'id', 'if', 'in', 'is', 'it', 'jo', 'ka', 'ki', 'la', 'li', 'lo', \ 'ma', 'me', 'mi', 'mm', 'mo', 'mu', 'my', 'na', 'ne', 'no', 'nu', 'od', 'oe', 'of', \ 'oh', 'oi', 'om', 'on', 'op', 'or', 'os', 'ow', 'ox', 'oy', 'pa', 'pe', 'pi', 'qi', \ 're', 'sh', 'si', 'so', 'ta', 'ti', 'to', 'uh', 'um', 'un', 'up', 'us', 'ut', 'we', 'wo', 'xi', 'xu', 'ya', 'ye', 'yo', 'za'] np.testing.assert_array_equal(out, expected)
# Allow repeated tiles? # TODO: should make this a flag to the solver all_tiles = tiles + tiles + tiles # Letters that must exist # (must have a v) pattern = '.*v.*' # Length restrictions # (must be at least 5 letters) func = lambda x: len(x) >= 5 # get a list of all possible words filename = get_dict_path() words = create_dict(filename) # find all the words that match the pattern temp = find_all_words(all_tiles, words, pattern='.*v.*') # apply the additional restrictions solution = find_all(temp, func=lambda x: len(x) >= 5) # print the solution print(solution) # score the solution # (one point per word, 3 points if all letters used) score = sum([1 if len(set(x)) < len(tiles) else 3 for x in solution]) print('{} Words for a final score of {} points!'.format( len(solution), score))
def test_pattern(self): out = scrab.find_all_words(self.tiles, self.words, pattern=r'a..$') np.testing.assert_array_equal(out, ['draws', 'roads', 'sward', 'woads', 'daws', 'oars', \ 'rads', 'raws', 'sard', 'wads', 'ward', 'wars', 'ado', 'ads', 'ars'])
def test_nominal(self): out = scrab.find_all_words(self.tiles, self.words) np.testing.assert_array_equal(out, self.out)