def generate_rand_dawg(nchars, nwords, wordlenpdf=None): """ Generate a random DAWG whose word lengths are distributed by function wordlenpdf, using gnerate_rand_lexicon above. input: nchars: number of characters in lexicon nwords: number of words in lexicon wordlenpdf: a function """ rand_lex = generate_rand_lexicon(nchars, nwords, wordlenpdf) G = DirectedGraph() G.parselex(rand_lex) trie_to_dawg(G) return G
of the algorithm. Random tile selections are unlikely to produce solutions. """ import sys sys.path.append('../') import random from collections import defaultdict import cPickle as pkl from graph import DirectedGraph, trie_to_dawg from bananagram import Bananagrams w = open('../../data/twl06.txt', 'r').read() #w = open('../../data/sowpods.txt', 'r').read() G = DirectedGraph() G.parselex(w) trie_to_dawg(G) print("DAWG Finished!") # Bananagrams tile frequency freq = [ 13, 3, 3, 6, 18, 3, 4, 3, 12, 2, 2, 5, 3, 8, 11, 3, 2, 9, 6, 9, 6, 3, 3, 2, 3, 2 ] chars = sorted(G.top.children.keys()) tiles = reduce(lambda x, y: x + y, [[chars[i] for j in range(f)] for i, f in enumerate(freq)]) B = Bananagrams(G) sizedict = {}
""" import sys sys.path.append('../') from graph import DirectedGraph, trie_to_dawg from board import Board #from bananagram import Bananagrams import bananagram as bg print('Testing lexicon and DAWG properties') lex = "dad at car cars cat cats do dog dogs done ear" lex += "ears eat eats deed ate as read area seat" # Test DAWG G = DirectedGraph() G.parselex(lex) trie_to_dawg(G) print('DAWG.downto works: {}'.format(G.downto('dad') is not None)) print('DAWG structure works: {}'.format(G.top['dad'] is G.top['area'])) # Test Board board = Board() ys = [0, 1, 2, 2, 2, 2, 3] xs = [3, 3, 0, 1, 2, 3, 2] ss = [s for s in 'easeatt'] #board.placeall(ys, xs, ss) # NOTE: I removed placeall so that I could test passing in a custom # board through kwarg! # It passed! #b = (ys, xs, ss)