def main(): """ Main program: Find all words of length 3 or greater on a boggle board. Args: none (but expect two arguments on command line) Returns: Nothing (but prints found words in alphabetical order, without duplicates, one word per line) """ dict_file, board_text = getargs() game_dict.read(dict_file) f.close() board = BoggleBoard(board_text) board_height, board_width = 4, 4 for x in range(board_width): for y in range(board_height): find_words(board, x, y, board.get_char(x, y)) results = board.results set_results = set(results) results = list(set_results) results.sort() final = [(item, score(item)) for item in results] if final: for elem in final: print(elem[0], elem[1]) # the word and its count sum_list = [elem[1] for elem in final] print('Total score: ', sum(sum_list)) else: print('None')
def main(): """ Main program: Find all words of length 3 or greater on a boggle board. Args: none (but expect two command line arguments - a string of 16 alph characters and a dictionary file) Returns: Nothing, but prints found words in alphabetical order, without duplicates, one word per line. Each word is scored and the sum of all words is printed """ dict_file, board_text = getargs() game_dict.read(dict_file) board = BoggleBoard(board_text) rows = 4 cols = 4 results = [] for row in range(rows): for col in range(cols): find_words(board, row, col, board.get_char(row, col), results) set_ = set(results) fin_list = list(set_) fin_list.sort() final = score(fin_list) print("Total score:", final)
def main(): """ Main program: Find all words of length 3 or greater on a boggle board. Args: none (but expect two arguments on command line) Returns: Nothing (but prints found words in alphabetical order, without duplicates, one word per line) """ dict_file, board_text = getargs() game_dict.read( dict_file ) board = BoggleBoard(board_text) global results results = [] l = [0,1,2,3] for r in l: for c in l: find_words(board, r, c) comeout = duplicate(results) total = 0 for word in comeout: numb = score(word) total += numb print(word + " " + str(numb)) print("Total score: " + str(total))
def test_include_requires_3_char_min(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertFalse(b.include_word("")) self.assertFalse(b.include_word("A")) self.assertFalse(b.include_word("AB")) self.assertTrue(b.include_word("ABC"))
def main(): """ Main program: Find all words of length 3 or greater on a boggle board. Args: none (but expect two arguments on command line) Returns: Nothing (but prints found words in alphabetical order, without duplicates, one word per line) """ dict_file, board_text = getargs() game_dict.read( dict_file ) board = BoggleBoard(board_text) results = [ ] #game_dict = game_dict.read( dict_file ) #KS: added this to initialize init_find_words = find_words(board, 0, 0, board.get_char(0,0), results)
def main(): """ Main program: Find all words of length 3 or greater on a boggle board. Args: none (but expect two arguments on command line) Returns: Nothing (but prints found words in alphabetical order, without duplicates, one word per line) """ dict_file, board_text = getargs() game_dict.read( dict_file ) board = BoggleBoard(board_text) results = [ ] for row in range(4): for col in range(4): init_find_words = find_words(board, row, col, board.get_char(row,col), results) print(results)
def main(): """Main program: Find all words of length 3 or greater on a boggle board. Parameters --------- Input: None pulls two arguments from the command line: "board" is the characters of board, in left-to-right reading order dict.txt is a file containing a list of words in alphabetical order Output: None but prints found words in alphabetical order, without duplicates, one word per line)""" global word_dict dict_file, board_text = getargs() # pulls args from command line word_dict = game_dict.read(dict_file) board = BoggleBoard(board_text) # Creates range to hit all possible x values on board. for x in range(board.board_height): # Creates range to hit all possible y values on board. for y in range(board.board_width): # runs recursive search beginning from each tile on the board. results.update(find_words(board, x, y, board.get_char(x,y))) final_list = score_list(results) total_score = 0 for x, y in sorted(final_list): # Prints each word with associated score. print("{} {}".format(x,y)) total_score += y print("Total score:", total_score)
def main(): """ Main program: Find all words of length 3 or greater on a boggle board. Args: none (but expect two arguments on command line) Returns: Nothing (but prints found words in alphabetical order, without duplicates, one word per line) """ dict_file, board_text = getargs() game_dict.read( dict_file ) board = BoggleBoard(board_text) results = [ ] total_score = 0 for i in range(0,4): for j in range(0,4): find_words(board,i,j,'',results) results = deadu(results) for word in results: print(word + ' ' + str(score(word))) total_score += score(word) print("Total Score " + str(total_score))
from boggle_board import BoggleBoard import sys boggle = BoggleBoard() while (True): choice = input("S! for shake, P! for print or word\n") if choice == "S!": boggle.shake() print("Board has been shaken up") elif choice == "P!": boggle.print_board() elif choice == "exit()": print("Goodbye!") break else: print( f"Board includes {choice.upper()}: {boggle.include_word(choice)}") print()
def test_include_word_too_long(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("ABCDHGFEIJKLPONM")) self.assertFalse(b.include_word("ABCDHGFEIJKLPONMR"))
def test_include_vertical(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("AEIM")) self.assertTrue(b.include_word("PLHD"))
def test_include_disjointed_returns_false(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertFalse(b.include_word("ABCKO")) self.assertFalse(b.include_word("DGA"))
def test_include_horizontal(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("ABCD")) self.assertTrue(b.include_word("HGFE"))
def test_include_lower_case(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("abcd"))
def test_include_repeat_returns_false(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertFalse(b.include_word("ABCDHGCD"))
class BoggleBoardTests(unittest.TestCase): boggle = BoggleBoard() def test_board_lengths(self): self.assertEqual(len(self.boggle.board), 16) def test_shake(self): board_copy = self.boggle.board.copy() self.boggle.shake() self.assertNotEqual(board_copy, self.boggle.board) def test_q(self): die = ['A', 'Q', 'C', 'D'] self.boggle.replace_q_in_row(die) self.assertEqual(die, ['A', 'Qu', 'C', 'D']) def test_include_horizontal(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("ABCD")) self.assertTrue(b.include_word("HGFE")) def test_include_vertical(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("AEIM")) self.assertTrue(b.include_word("PLHD")) def test_include_diagonal(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("AFKP")) self.assertTrue(b.include_word("DGJM")) def test_include_snake(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("ABFEJOLG")) def test_include_repeat_returns_false(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertFalse(b.include_word("ABCDHGCD")) def test_include_lower_case(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("abcd")) def test_include_disjointed_returns_false(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertFalse(b.include_word("ABCKO")) self.assertFalse(b.include_word("DGA")) def test_include_requires_3_char_min(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertFalse(b.include_word("")) self.assertFalse(b.include_word("A")) self.assertFalse(b.include_word("AB")) self.assertTrue(b.include_word("ABC")) def test_include_word_too_long(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("ABCDHGFEIJKLPONM")) self.assertFalse(b.include_word("ABCDHGFEIJKLPONMR"))
def test_include_snake(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("ABFEJOLG"))
def test_include_diagonal(self): b = BoggleBoard() b.board = list('ABCDEFGHIJKLMNOP') self.assertTrue(b.include_word("AFKP")) self.assertTrue(b.include_word("DGJM"))