Ejemplo n.º 1
0
def main():
    parser = ArgumentParser(description="Solve a given boggle board")
    parser.add_argument("--board", dest="board", help="a list of 16 characters making up \
            the board - if not provided, this is generated randomly")
    args = parser.parse_args()

    if (args.board):
        board = Boggle(args.board)
    else:
        board = random_board()

    trie = build_english_language_trie()
    solutions = board.solve(trie)
    num_words = len(solutions)
    points = count_points(solutions)
    sorted_words = sorted(solutions.keys())

    # render report to HTML
    env = Environment(loader=PackageLoader('boggle', 'templates'))
    template = env.get_template('report.html')

    # setup solutions for render:
    formatted_solutions = {}
    for word in solutions:
        formatted_pos = ['%d-%d' % pos for pos in solutions[word]]
        formatted_solutions[word] = formatted_pos

    output = template.render(grid=board.grid, solutions=formatted_solutions, num_words=num_words, points=points, sorted_words=sorted_words, size=Boggle.size)
    print output
Ejemplo n.º 2
0
def main():
    welcome = """
    #############################################
    ### WELCOME TO THE SUPER BYTE BOGGLE GAME ###
    #############################################
    
    """
    print(welcome)
    try:
        npt_dice_type = int(input("Would you like to play with the classic or new dice's type? (type '1' for Classic or '2' for New): "))
        if npt_dice_type not in [1, 2]:
            raise Exception()
    except:
        print("Invalid dice type.")
        return
    
    boggle = Boggle()
    boggle.start(npt_dice_type)
    print(boggle)
    
    boggle.user_words = get_user_answers(60*3)
    
    print('Wait, as soon the intern come back with my coffe he might start checking your answers...')
    boggle.get_all_words() #save all possible words based on dictionary on boggle.word_list
    points = 0
    valid_on_board = []
    for word in boggle.user_words:
        if boggle.has_word(word):
            valid_on_board.append(word)
    valid_on_dict = set(valid_on_board).intersection(boggle.word_list)
    for word in valid_on_dict:
        point = boggle.calculate_points(word)
        points += point
        print("{} = {} points".format(word, point))
    
    print("You total score is {} points!".format(points))
    print("Those were all possible words: ")
    print(boggle.word_list)
    print("Better lucky next time :)")
Ejemplo n.º 3
0
class TestBoggle(unittest.TestCase):
    
    def setUp(self):
        self.board = Boggle('./4x4_board.txt')

    def tearDown(self):
        self.board = None

    def test_board_size(self):
        self.assertEqual(len(self.board.letters), 16)

    def test_word_in_board(self):
        self.assertTrue(self.board.find_word('alien'))
        self.assertTrue(self.board.find_word('tane'))
        self.assertTrue(self.board.find_word('genitals'))

    def test_word_not_in_board(self):
        self.assertFalse(self.board.find_word('zambapollos'))
        self.assertFalse(self.board.find_word('caradura'))
        self.assertFalse(self.board.find_word('fuoiuas'))
Ejemplo n.º 4
0
 def setUp(self):
     self.board = Boggle('./4x4_board.txt')
Ejemplo n.º 5
0
board.clear()
assert len(board.board) == 0, "Board should be empty after calling clean()."

board.start()
assert type(board.get_item(1,2)) == Dice, "Should return the the 3rd item from the second row, an Dice object"

assert len(board.get_surrounds(3,3)) == 3, "Should return a list with 3 Dices, the surrounds of the dice on 4th row and 4th column."
assert len(board.get_surrounds(1,1)) == 8, "Should return a list with 8 Dices, the surrounds of the dice on 2nd row and 2nd column."
assert len(board.get_surrounds(0,2)) == 5, "Should return a list with 5 Dices, the surrounds of the dice on 1st row and 3rd column."


### Boggle tests ###
from boggle import Boggle

boggle = Boggle()
boggle.start()
assert type(boggle) == Boggle, "Should be an instance of boggle"

word = ''
word += str(boggle.get_item(0,0))
word += str(boggle.get_item(0,1))
word += str(boggle.get_item(0,2))
print(boggle)
print(word)
assert boggle.has_word(word) == True, "Should be True as the 'word' is the first 3 letters from 1st row"

word = ''
word += str(boggle.get_item(1,1))
word += str(boggle.get_item(2,2))
word += str(boggle.get_item(3,3))
Ejemplo n.º 6
0
"""Main entry point of boggle-bot."""
import getpass
import os
import sys
import time

from boggle import Boggle
from wordplays import Wordplays

MAX_CONSECUTIVE_ERRORS = 3

module_dir = os.path.dirname(__file__)
Boggle.load_dictionary(module_dir + '/dict.list')

username = input('Enter username: ')
password = getpass.getpass(prompt='Enter password: ')

with Wordplays() as wp:
    try:
        if not wp.login(username=username, password=password):
            print('Login unsuccessful.', file=sys.stderr)
            print('Exiting.', file=sys.stderr)
            sys.exit(1)
    except RuntimeError as e:
        print('Error:', e, file=sys.stderr)
        print('Exiting.', file=sys.stderr)
        sys.exit(1)

    print('Login successful.\n')

    # Continuously solve puzzles until too many consecutive errors are