1 |
2 |
marius_mtm |
#!/sbin/python
|
2 |
|
|
|
3 |
|
|
# Marius TIVADAR (c) Feb, 2009
|
4 |
|
|
|
5 |
|
|
RED = 'R'
|
6 |
|
|
BLUE = 'B'
|
7 |
|
|
INDENT = 4
|
8 |
|
|
DIAG = {0: 'ZEROP', 1: 'DOWN45P', 2: 'DOWN', 3: 'DOWN45M', 4: 'ZEROM', 5: 'UP45M', 6:'UP', 7: 'UP45P'}
|
9 |
|
|
|
10 |
|
|
def write_equations(qq, sq):
|
11 |
|
|
# C squares
|
12 |
|
|
|
13 |
|
|
C = [['' for z in range(8)] for q in range(len(qq))]
|
14 |
|
|
axes = [(1, 1), (1, -1), (-1,-1), (-1,1), (0,1), (1,0), (-1,0), (0, -1)]
|
15 |
|
|
# axes = [(0,1)]
|
16 |
|
|
|
17 |
|
|
for k in range(len(qq)): # pentru toate pozitiile din lista
|
18 |
|
|
_C = ['']*len(qq)
|
19 |
|
|
for m in range(len(axes)): # toate directiile
|
20 |
|
|
for i in range(0,8): # dimensiunea tablei de joc
|
21 |
|
|
_C[k] = '';
|
22 |
|
|
x = qq[k][0]
|
23 |
|
|
y = qq[k][1]
|
24 |
|
|
|
25 |
|
|
for j in range(0, i):
|
26 |
|
|
x += axes[m][0]
|
27 |
|
|
y += axes[m][1]
|
28 |
|
|
if ((x >= 0 and x < 8) and (y >= 0 and y < 8)):
|
29 |
|
|
_C[k] += '%(red)s[%(i)d*8 + %(j)d] && ' %{'red':RED, 'i': x, 'j': y}
|
30 |
|
|
else:
|
31 |
|
|
_C[k] = ''
|
32 |
|
|
|
33 |
|
|
# AND cu player, pentru a flanca
|
34 |
|
|
x += axes[m][0]
|
35 |
|
|
y += axes[m][1]
|
36 |
|
|
|
37 |
|
|
if ((x >= 0 and x < 8) and (y >= 0 and y < 8)):
|
38 |
|
|
if _C[k]:
|
39 |
|
|
_C[k] += '%(blue)s[%(i)d*8 + %(j)d]'% {'blue': BLUE, 'i': x, 'j': y}
|
40 |
|
|
# generez SAU
|
41 |
|
|
C[k][m] += _C[k].join('()') + ' ||' + '\n'
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
for k in range(0,len(qq)):
|
45 |
|
|
for m in range(len(axes)):
|
46 |
|
|
if C[k][m]:
|
47 |
|
|
g = ('(\n' + C[k][m].strip('||\n') + '\n);').split('\n')
|
48 |
|
|
C[k][m] = '\n'.join([' '*(13 + INDENT) + g[i] for i in range(len(g))])
|
49 |
|
|
C[k][m] = ' '*INDENT + '%(map)s[%(i)d][%(j)d][%(direction)s] = (!%(red)s[%(i)d*8 + %(j)d] && !%(blue)s[%(i)d*8 + %(j)d]) && \n\n%(expr)s' %{'map':'M', 'i':qq[k][0], 'j':qq[k][1], 'direction':DIAG[m], 'red':RED, 'blue':BLUE, 'expr':C[k][m]}
|
50 |
|
|
else:
|
51 |
|
|
C[k][m] = ' '*INDENT + '%(map)s[%(i)d][%(j)d][%(direction)s] = 1\'b0;' %{'map':'M', 'i':qq[k][0], 'j':qq[k][1], 'direction':DIAG[m], 'red':RED, 'blue':BLUE}
|
52 |
|
|
|
53 |
|
|
|
54 |
|
|
print '\n'
|
55 |
|
|
print '// Expresii generate pentru patrate ' + sq
|
56 |
|
|
for k in range(0,len(qq)):
|
57 |
|
|
for m in range(len(axes)):
|
58 |
|
|
if C[k][m]:
|
59 |
|
|
print C[k][m]
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
write_equations([(0,0), (0,7), (7,7), (7,0)], 'A') # A
|
63 |
|
|
write_equations([(0,1), (0,6), (1,7), (6,7), (7,6), (7,1), (6,0), (1,0)], 'B') # B
|
64 |
|
|
write_equations([(0,2), (0,5), (2,7), (5,7), (7,5), (7,2), (5,0), (2,0)], 'C') # C
|
65 |
|
|
write_equations([(0,3), (0,4), (3,7), (4,7), (7,4), (7,3), (4,0), (3,0)], 'D') # D
|
66 |
|
|
write_equations([(1,1), (1,6), (6,6), (6,1)], 'E') # E
|
67 |
|
|
write_equations([(1,2), (1,5), (2,6), (5,6), (6,5), (6,2), (5,1), (2,1)], 'F') # F
|
68 |
|
|
write_equations([(1,3), (1,4), (3,6), (4,6), (6,4), (6,3), (4,1), (3,1)], 'G') # G
|
69 |
|
|
write_equations([(2,2), (2,5), (5,5), (5,2)], 'H') # H
|
70 |
|
|
write_equations([(2,3), (2,4), (3,5), (4,5), (5,4), (5,3), (4,2), (3,2)], 'I') # I
|
71 |
|
|
|
72 |
|
|
for c in [(3,3), (3,4), (4,3), (4,4)]:
|
73 |
|
|
print ' '*INDENT + '%(map)s[%(i)d][%(j)d][7:0] = 8\'b00000000;' %{'map':'M', 'i':c[0], 'j':c[1]}
|
74 |
|
|
|
75 |
|
|
for q in range(8):
|
76 |
|
|
print 'RES_D[%(i)d*7 + %(j)d : %(j)d*7 + %(j)d] = '%{'i':q+1, 'j':q} + ''.join(['|M[' + str(q) + '][' + str(7-i) + '], ' for i in range(8)])[:-2].join('{}') + ';'
|