-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.py
63 lines (58 loc) · 1.88 KB
/
init.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
import time
class chess():
def __init__(self, op: int, id: int):
self.op = op
self.id = id
def load(QW, filepath):
QW.statusBar().showMessage('Loading...')
time.sleep(0.5)
filer = open(filepath, "r")
da = filer.readlines()
filer.close()
r = [[chess(0, 0) for j in range(10)] for i in range(11)]
r2 = [[0]*4 for i in range(500)]
tur = (int)(da[0].split(' ')[0])
for i in range(10):
for j in range(9):
r[i+1][j+1].op = (int)(da[i+1].split(' ')[2*j])
r[i+1][j+1].id = (int)(da[i+1].split(' ')[2*j+1])
np = (int)(da[11].split(' ')[0])
for i in range(np):
for j in range(4):
r2[i][j] = (int)(da[12+i].split(' ')[j])
return tur, r, np, r2
def save(filepath, tur, r, np, r2):
filew = open(filepath, "w")
filew.write(str(tur)+'\n')
for i in range(10):
for j in range(9):
filew.write(str(r[i+1][j+1].op)+' '+str(r[i+1][j+1].id)+' ')
filew.write('\n')
filew.write(str(np)+'\n')
for i in range(np):
for j in range(4):
filew.write(str(r2[i][j])+' ')
filew.write('\n')
filew.close()
def convert(r):
pos = [[0]*2 for i in range(32)]
for i in range(10):
for j in range(9):
if r[i+1][j+1].op == 0:
continue
if r[i+1][j+1].op == 2:
temp = 16
else:
temp = 0
if r[i+1][j+1].id == 1:
pos[temp][0] = i+1
pos[temp][1] = j+1
else:
tep = temp + r[i+1][j+1].id*2 - 3
# print(r[i+1][j+1].op, r[i+1][j+1].id, tep)
while pos[tep][0] != 0:
tep += 1
# print(tep)
pos[tep][0] = i+1
pos[tep][1] = j+1
return pos