Attachment 'Ricochet-Robots-ENCODING.txt'
Download 1 dir(west, -1, 0).
2 dir(east, 1, 0).
3 dir(north, 0,-1).
4 dir(south, 0, 1).
5
6 dl(west, -1).
7 dl(north,-1).
8 dl(east, 1).
9 dl(south, 1).
10
11 dir(west, row).
12 dir(east, row).
13 dir(north,col).
14 dir(south,col).
15
16 dir(D) :- dir(D,_).
17
18 robot(R) :- pos(R,_,_).
19
20 pos(R,row,I,0) :- pos(R,I,_).
21 pos(R,col,J,0) :- pos(R,_,J).
22
23 barrier(I+1,J,west ) :- barrier(I,J,east ), dim(I), dim(J), dim(I+1).
24 barrier(I,J+1,north) :- barrier(I,J,south), dim(I), dim(J), dim(J+1).
25 barrier(I-1,J,east ) :- barrier(I,J,west ), dim(I), dim(J), dim(I-1).
26 barrier(I,J-1,south) :- barrier(I,J,north), dim(I), dim(J), dim(I-1).
27
28 conn(D,I,J) :- dir(D,col), dir(D,_,DJ), not barrier(I,J,D), dim(I), dim(J), dim(J+DJ).
29 conn(D,J,I) :- dir(D,row), dir(D,DI,_), not barrier(I,J,D), dim(I), dim(J), dim(I+DI).
30
31 step(1).
32 step(X+1) :- step(X), length(L), X < L.
33 %step(1..X) :- length(X).
34
35
36 1<= { selectRobot(R,T) : robot(R) } <=1 :- step(T).
37 1<= { selectDir(D,O,T) : dir(D,O) } <=1 :- step(T).
38
39 go(R,D,O,T) :- selectRobot(R,T), selectDir(D,O,T).
40 go_(R,O,T) :- go(R,_,O,T).
41 go(R,D,T) :- go(R,D,_,T).
42
43 sameLine(R,D,O,RR,T) :- go(R,D,O,T), pos(R,-O,L,T-1), pos(RR,-O,L,T-1), R != RR.
44 blocked(R,D,O,I+DI,T) :- go(R,D,O,T), pos(R,-O,L,T-1), not conn(D,L,I), dl(D,DI), dim(I), dim(I+DI).
45 blocked(R,D,O,L,T) :- sameLine(R,D,O,RR,T), pos(RR,O,L,T-1).
46
47 reachable(R,D,O,I, T) :- go(R,D,O,T), pos(R,O,I,T-1).
48 reachable(R,D,O,I+DI,T) :- reachable(R,D,O,I,T), not blocked(R,D,O,I+DI,T), dl(D,DI), dim(I+DI).
49
50 :- go(R,D,O,T), pos(R,O,I,T-1), blocked(R,D,O,I+DI,T), dl(D,DI).
51 :- go(R,D,O,T), go(R,DD,O,T-1).
52
53 pos(R,O,I,T) :- reachable(R,D,O,I,T), not reachable(R,D,O,I+DI,T), dl(D,DI).
54 pos(R,O,I,T) :- pos(R,O,I,T-1), not go_(R,O,T), step(T).
55
56 selectDir(O,T) :- selectDir(D,O,T).
57
58 :- target(R,I,_), not pos(R,row,I,X), length(X).
59 :- target(R,_,J), not pos(R,col,J,X), length(X).
Attached Files
You are not allowed to attach a file to this page.