typos
[mc1516pa.git] / code / SokRunner.py
1 import os, errno
2 import subprocess
3
4 #solver path
5 solverpath = "C:\\Users\\Alex Fedotov\\Documents\\Studies\\Model Checking\\Assignments\\Solver\\"
6
7 #paths to folders with sokoban screens
8 paths = ["C:\\Users\\Alex Fedotov\\Documents\\Studies\\Model Checking\\Assignments\\Sokoban\\screens",
9 ]
10
11 #path to output folder (base)
12 output = "C:\\Users\\Alex Fedotov\\Documents\\Studies\\Test"
13
14 commands = ["C:\\Users\\Alex Fedotov\\Documents\\Studies\\Model Checking\\Assignments\\Solver\\solver.exe"]
15
16 boxbound = 3
17 sizebound = 60
18 timebound = 10
19
20 def checkPaths():
21 isOk = True
22 for path in paths:
23 if not os.path.isdir(path):
24 isOk = False
25 print("You specified a wrong path: %s" % path)
26 return isOk
27
28 def checkScreen(screenpath):
29 scrSize = 0
30 scrBox = 0
31 with open(screenpath,"r") as src:
32 for line in src:
33 scrSize += len(line.rstrip())
34 scrBox += line.count('$')
35 scrBox += line.count('*')
36 src.close()
37 return boxbound >= scrBox and sizebound >= scrSize
38
39 for com in commands:
40 if checkPaths():
41 out = open(output + "\\results.txt", "w")
42 for path in paths:
43 all_rs = os.listdir(path)
44 for test in all_rs:
45 input_path = path + "\\" + test
46 os.makedirs(output, exist_ok=True)
47 os.chdir(solverpath)
48 if checkScreen(input_path):
49 runcommand = []
50 runcommand.append(com)
51 runcommand.append(input_path)
52 #to be continued...
53 proc = subprocess.run(runcommand, stdout=subprocess.PIPE, universal_newlines=True)
54 proc.wait()
55 out.write(test + ":" + proc.stdout)
56 print(test + ":" + proc.stdout)
57 #input("Press enter to continue...")
58 out.close();