-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReadFile.py
105 lines (96 loc) · 3.15 KB
/
ReadFile.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import cmd
from Box import Box
from Tools import output_file
class ReadFile(cmd.Cmd):
prompt = 'Candy '
@staticmethod
def do_manual(self):
input_order = []
with open('./input.txt', 'rt') as f:
for line in f:
line = line.strip('\n')
c = line.split(' ')
input_order.append(c)
output_str = ''
for line in input_order:
box = Box(line)
box.manual_run()
output_str += box.output_string()
print('%dth puzzle complete.')
counter = 0
flag_counter = 0
for i in output_str.splitlines():
if flag_counter % 2 is 0:
counter += len(i)
flag_counter += 1
counter = str(counter)
output_str += counter
output_file(output_str)
@staticmethod
def do_auto(self):
level_num = input('choose level ')
level_num = int(level_num)
input_order = []
if level_num is 1:
with open('./input1.txt', 'rt') as f:
for line in f:
line = line.strip('\n')
c = line.split(' ')
input_order.append(c)
elif level_num is 2:
with open('./input2.txt', 'rt') as f:
for line in f:
line = line.strip('\n')
c = line.split(' ')
input_order.append(c)
elif level_num is 3:
with open('./input3.txt', 'rt') as f:
for line in f:
line = line.strip('\n')
c = line.split(' ')
input_order.append(c)
elif level_num is 4:
with open('./input4.txt', 'rt') as f:
for line in f:
line = line.strip('\n')
c = line.split(' ')
input_order.append(c)
elif level_num is 0:
with open('./input.txt', 'rt') as f:
for line in f:
line = line.strip('\n')
c = line.split(' ')
input_order.append(c)
index = 0
output_str = ''
for line in input_order:
box = Box(line)
box.auto_run()
output_str += box.output_string()
index += 1
if box.time_out:
print('%dth puzzle time-out.' % index)
else:
print('%dth puzzle complete.' % index)
counter = 0
flag_counter = 0
for i in output_str.splitlines():
if flag_counter % 2 is 0:
counter += len(i)
flag_counter += 1
counter = str(counter)
output_str += counter
output_str += '\n'
# sum_time = 0
# for i in output_str.splitlines():
# if 'ms' in i:
# m_position = i.index('m')
# sum_time += float(i[0:m_position])
# output_str += str(sum_time)
# output_str += 'ms\n'
output_file(output_str, level_num)
@staticmethod
def do_exit(self):
return True
if __name__ == '__main__':
ReadFile().cmdloop()