示例#1
0
def play_game(trie):
    letters = Cubes().shuffle()
    board = Board(letters)

    print board
    print 'You have 3 minutes - press Ctrl-C to finish early'

    bar = ProgressBar(60)
    try:
        event = Event()
        for i in range(60):
            bar.show(i)
            event.wait(3)
        bar.finish()
        os.system('say "time is up, stop boggling"')
    except KeyboardInterrupt:
        pass

    raw_input('\nPress <ENTER> to see answers')

    results = board_search(board, trie)
    answers = Answers()
    answers.add(results)

    print answers
示例#2
0
def show_answers(trie, letters):
    board = Board(letters)

    results = board_search(board, trie)

    answers = Answers()
    answers.add(results)

    print board
    print answers
示例#3
0
def show_answers_hex(trie, input_str):
    row_letters, row_starts = parse_letters_hex(input_str)
    board = HexBoard(row_letters, row_starts)
    print board

    results = board_search(board, trie)

    answers = Answers()
    answers.add(results)

    print answers
示例#4
0
class AnswersTest(unittest.TestCase):
    def setUp(self):
        self.answers = Answers()

    def test_empty(self):
        self.assertEquals(0, self.answers._calc_points())

    def test_duplicates(self):
        word = 'abc'

        self.answers.add([word, word, word])
        self.assertEquals(1, self.answers._calc_points())

        self.answers.add([word])
        self.assertEquals(1, self.answers._calc_points())

    def test_dict(self):
        self.answers.add(['aaa', 'bbb', 'cccc'])

        d = self.answers._make_dict()

        self.assertEquals(['aaa', 'bbb'], d[3])
        self.assertEquals(['cccc'], d[4])