def solve(): answer = tk.Tk() answer.title('Boggle Solutions') words = bg.solve() lengths = [len(word) for word in words] mx = max(lengths) mn = min(lengths) listboxes = [] scrollbars = [] for i in range(mn, mx + 1): scrollbars.append(tk.Scrollbar(answer)) listboxes.append( tk.Listbox(answer, width=i + 1, font="Helvetica 20 bold", yscrollcommand=scrollbars[-1].set)) # listboxes[-1].grid(column=2*(i-mn), row=0) # scrollbars[-1].grid(column=2*(i-mn)+1,row = 0) listboxes[-1].pack(side=tk.LEFT, fill=tk.Y) scrollbars[-1].pack(side=tk.LEFT, fill=tk.Y) scrollbars[-1].config(command=listboxes[-1].yview) for word in words: if len(word) == i: listboxes[-1].insert(tk.END, word) answer.lift()
def test_boggle(): """Checks for twelve known words in a specific board.""" board = """CATER XLUAW BDFGH IJKMN OPQST""" board2 = """CATERWAULING ASDFGHJKLZXC QAZWSXEDCRFV TGBYHNUJMIKL OKMIJNUHBYGV TFCRDXESZWAQ ASDFGHJKLZXC QAZWSXEDCRFV TGBYHNUJMIKL OKMIJNUHBYGV TFCRDXESZWAQ ABABABABABAB""" known_words = set(["cat", "cater", "caterwaul", "ate", "tea", "eta", "late", "lute", "later", "wag", "jib", "poi"]) found_words = set() for word in solve(board): assert word in known_words found_words.add(word) assert known_words == found_words
def get_words(self): key = 'words_%d' % self.id result = cache.get(key) if result is None: result = boggle.solve(self.rows, self.min_length) cache.set(key, result, timeout=300) return result
def main(): usage = """Usage: %prog [board_letters] Example: %prog T N N H I G N E S G E I C A H N""" parser = optparse.OptionParser(usage=usage) options, args = parser.parse_args() if len(args) is not 16: print "You typed in the wrong number of letters, %s should be 16try again" % len(args) return boggle.load_dictionary() if args: board = boggle.make_board(width=WIDTH, height=HEIGHT, letters=' '.join(args)) boggle.print_board(board) print '----' #precalculate word list, optimize by doing robot while building this up words, locmap = boggle.solve(board) wordList = list(words) wordList.sort(cmp=bylength) for i in wordList: print "( %s -> %s )" % (i, locmap[i]) locs = locmap[i].split(",") finger.down(*convertToCoordinates(locs[0])) for loc in locs[1:]: finger.drag(*convertToCoordinates(loc)) finger.up() print
def test_boggle(): """Checks for twelve known words in a specific board.""" board = """CATER XLUAW BDFGH IJKMN OPQST""" known_words = set([ "cat", "cater", "caterwaul", "ate", "tea", "eta", "late", "lute", "later", "wag", "jib", "poi" ]) found_words = set() for word in solve(board): assert word in known_words found_words.add(word) assert known_words == found_words