File: solitaire.lp

package info (click to toggle)
gringo 4.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,260 kB
  • ctags: 10,755
  • sloc: cpp: 55,049; python: 629; yacc: 569; sh: 124; makefile: 23
file content (33 lines) | stat: -rw-r--r-- 1,003 bytes parent folder | download
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
#include <iclingo>.

#show jump/4.

#program base.

stone(X,Y,0) :- stone(X,Y).
field(X,Y,D) :- field(X,Y), field(X+2*DX,Y+2*DY), dir(D,DX,DY).

#program cumulative(t).

1 { jump(X,Y,D,t) : field(X,Y,D) }.
remove(X+DX,Y+DY,t) :- jump(X,Y,D,t), dir(D,DX,DY).

 :- jump(X,Y,D,t), not stone(X,Y,t-1).
 :- jump(X,Y,D,t), stone(X+2*DX,Y+2*DY,t-1), dir(D,DX,DY).
 :- remove(X,Y,t), not stone(X,Y,t-1), dir(D,DX,DY).

 :- jump(X,Y,D,t), jump(X,Y,D',t), D != D'.
 :- jump(X,Y,D,t), jump(X',Y',D',t), dir(D,DX,DY), dir(D',DX',DY'), X+DX == X'+DX', Y+DY == Y'+DY', D != D'.
 :- jump(X,Y,D,t), jump(X',Y',D',t), dir(D,DX,DY), dir(D',DX',DY'), X+2*DX == X'+2*DX', Y+2*DY == Y'+2*DY', D != D'.
 :- jump(X,Y,D,t), remove(X,Y,t).

 :- fix_jump(X,Y,D,t), not jump(X,Y,D,t).

stone(X+2*DX,Y+2*DY,t) :- jump(X,Y,D,t), dir(D,DX,DY).
stone(X,Y,t)           :- stone(X,Y,t-1), not jump(X,Y,_,t), not remove(X,Y,t).

#external query(t).

 :- query(t), goal(X,Y), not stone(X,Y,t).
 :- query(t), not goal(X,Y), stone(X,Y,t).