Exemple #1
0
 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"))
Exemple #2
0
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))
Exemple #3
0
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))
Exemple #4
0
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()
Exemple #5
0
 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"))
Exemple #6
0
 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"))
Exemple #7
0
 def test_include_repeat_returns_false(self):
     b = BoggleBoard()
     b.board = list('ABCDEFGHIJKLMNOP')
     self.assertFalse(b.include_word("ABCDHGCD"))
Exemple #8
0
 def test_include_lower_case(self):
     b = BoggleBoard()
     b.board = list('ABCDEFGHIJKLMNOP')
     self.assertTrue(b.include_word("abcd"))
Exemple #9
0
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"))
Exemple #10
0
 def test_include_snake(self):
     b = BoggleBoard()
     b.board = list('ABCDEFGHIJKLMNOP')
     self.assertTrue(b.include_word("ABFEJOLG"))
Exemple #11
0
 def test_include_diagonal(self):
     b = BoggleBoard()
     b.board = list('ABCDEFGHIJKLMNOP')
     self.assertTrue(b.include_word("AFKP"))
     self.assertTrue(b.include_word("DGJM"))
Exemple #12
0
 def test_include_vertical(self):
     b = BoggleBoard()
     b.board = list('ABCDEFGHIJKLMNOP')
     self.assertTrue(b.include_word("AEIM"))
     self.assertTrue(b.include_word("PLHD"))
Exemple #13
0
 def test_include_horizontal(self):
     b = BoggleBoard()
     b.board = list('ABCDEFGHIJKLMNOP')
     self.assertTrue(b.include_word("ABCD"))
     self.assertTrue(b.include_word("HGFE"))