-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.py
62 lines (49 loc) · 1.05 KB
/
cli.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
import time
class Cli:
'''
Handles the command line interface for SlickSudoku
'''
def __init__(self, board, solver):
self.board = board
self.solver = solver
def start(self):
'''
Starts the command line interface loop
Args:
None
Returns:
None
'''
while True:
cmd = input("Please enter a move (ex. B3 2), \"solve\", \"show\", or \"end\": ")
if cmd == "solve":
start = time.time()
try:
self.solver.solve()
except:
print("Unsolvable from here")
continue
end = time.time()
print("")
print("Solved in: {:f} seconds".format(end - start))
self.board.print()
break
elif cmd == "show":
self.board.print()
elif cmd == "end":
print("Bye!")
break
else:
cmds = cmd.split(" ")
if len(cmds) == 2:
index = self.board.get_index_from_label(cmds[0])
if index == -1:
print("Invalid move")
else:
try:
value = int(cmds[1])
self.board.play_move(index, value)
except:
print("Invalid move")
else:
print("Invalid move")