-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
57 lines (47 loc) · 1.29 KB
/
main.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
__author__ = 'benoit'
import os, sys, getopt
import datetime as dt
from morpion.game import *
from morpion.ui import *
def main(argv):
usage = 'python main.py [-s] [-f filename] \n -s: launch solver without ui \n -f: specify filename'
print('main')
debut = dt.datetime.now()
print('Starting at: ' + str(debut))
try:
opts, args = getopt.getopt(argv,"sf:d")
except getopt.GetoptError:
print(usage)
sys.exit(2)
mode = 'ui'
maxMoves, depth = 1000, 2
filename = None
for opt, arg in opts:
if opt == '-h':
print(usage)
sys.exit()
elif opt in ("-s", "--solve"):
mode = 'solver'
maxMoves = int(arg) if args else 1000000000
elif opt in ("-f", "--file"):
filename = arg
elif opt in ("-d", "--depth"):
mode = "depth"
depth = int(arg)
sol = Solitaire()
if filename:
file = open(filename,'rb')
sol = Solitaire.loadFromFile(filename)
file.close()
else:
sol = Solitaire()
if mode == 'solver':
solver = Solver(sol)
solver.solve()
sol.saveToFile()
else:
ui = SolitaireUI(sol)
ui.show()
if __name__ == '__main__':
args = sys.argv[1:]
main(args)