-
Notifications
You must be signed in to change notification settings - Fork 2
/
boggle.py
68 lines (51 loc) · 1.44 KB
/
boggle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import sys
import time
import signal
import os
from trie import Trie
from board import Board
from cubes import Cubes
from board_search import board_search
from answers import Answers
from progress_bar import ProgressBar
from threading import Event
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
def show_answers(trie, letters):
board = Board(letters)
results = board_search(board, trie)
answers = Answers()
answers.add(results)
print board
print answers
if __name__ == '__main__':
print 'Loading word list, please wait...'
trie = Trie()
for w in open('resources/words.txt').readlines():
word = w.strip()
if len(word) > 2:
trie.add(word.upper())
if len(sys.argv) > 1:
# Convert the command-line argument into a list of lists of letters
letters = map(list, sys.argv[1].upper().split(' '))
show_answers(trie, letters)
else:
play_game(trie)