From caea87d274fbe9abf0bfb43c980b0a297721c842 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Fri, 1 Jun 2018 16:35:23 -0700 Subject: [PATCH] Print board in boggle --- dotfiles/lib/python/boggle.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/dotfiles/lib/python/boggle.py b/dotfiles/lib/python/boggle.py index a021bf2b..e3292201 100644 --- a/dotfiles/lib/python/boggle.py +++ b/dotfiles/lib/python/boggle.py @@ -42,6 +42,15 @@ def build_board(size=4): ] +def board_string(board_to_draw): + border_line = "+{0}+".format((len(board_to_draw[0]) * 2 - 1) * "-") + return "{border_line}\n{contents}\n{border_line}".format( + contents="\n".join("|{0}|".format(" ".join(letter_line)) + for letter_line in board_to_draw), + border_line=border_line, + ) + + def build_trie(): node = TrieNode() with open('/usr/share/dict/words') as the_file: @@ -57,7 +66,7 @@ class Boggle(object): @classmethod def new_random(cls, trie): - return cls(build_board(), trie) + return cls(build_Board(), trie) def __init__(self, board, trie): self.height = len(board) @@ -154,5 +163,5 @@ def build_board_from_dice_roll(dice=None, row_size=4): if __name__ == '__main__': dict_trie = build_trie() board = build_board_from_dice_roll() - print(board) + print(board_string(board)) print(list(Boggle(board, dict_trie).run()))