2 #pylint: disable-msg=too-many-locals,invalid-name
6 """Generates the yices code for peg solitaire"""
7 pos
= [(x
, y
) for x
in range(7) for y
in range(7) if
8 not ((x
< 2 and y
< 2) or # exclude topleft
9 (x
> 4 and y
> 4) or # exclude bottomright
10 (x
> 4 and y
< 2) or # exclude topright
11 (x
< 2 and y
> 4)) # exclude bottomleft
14 (2, 0), (4, 0), (0, 2), (0, 4), (6, 2), (6, 4), (2, 6), (4, 6)]
19 iterations
= len(pos
)-len(holes
)
20 posp
= [p
for p
in pos
if p
not in ill_middles
]
29 """.format('\n\t'.join(' '.join('(i{}x{}y{})'.format(i
, x
, y
)
31 for i
in range(iterations
)))
33 print ' '.join('(not i0x{}y{})'.format(x
, y
) for x
, y
in holes
),
34 print ' '.join('i0x{}y{}'.format(x
, y
)
35 for x
, y
in pos
if (x
, y
) not in holes
)
38 for i
in range(1, iterations
):
39 print ';Iteration {}'.format(i
)
43 if mx
== sx
and my
== sy
:
46 if (ex
== sx
and ey
== sy
)or (ex
== mx
and ey
== my
):
48 if not ((sy
== my
and my
== ey
and sx
== mx
+1 and
50 (sy
== my
and my
== ey
and sx
== mx
-1 and
52 (sx
== mx
and mx
== ex
and sy
== my
+1 and
54 (sx
== mx
and mx
== ex
and sy
== my
-1 and
58 print ('i{0}x{1}y{2} '
60 '(not i{0}x{5}y{6})').format(i
-1,
61 sx
, sy
, mx
, my
, ex
, ey
)
62 print ('(not i{0}x{1}y{2}) '
64 'i{0}x{5}y{6}').format(i
, sx
, sy
, mx
, my
, ex
, ey
)
66 if not((ox
== sx
and oy
== sy
) or
67 (ox
== mx
and oy
== my
) or
68 (ox
== ex
and oy
== ey
)):
69 print '(= i{0}x{1}y{2} i{3}x{1}y{2})'.format(
74 print ';Negated winning condition'
75 print 'i{}x{}y{}'.format(iterations
-1, winning
[0], winning
[1]),
76 print ' '.join('(not i{}x{}y{})'.format(iterations
-1, x
, y
)
77 for x
, y
in pos
if (x
, y
) != winning
)
81 if __name__
== '__main__':