# Encoding 15-puzzle_chk.lp

Name 15-puzzle_chk.lp [Root]    Miscellaneous (45)    ASP Contest 09 (45) Martin Gebser Martin Gebser and Roland Kaminski 2009-03-13 21:35 2009-03-13 21:39 No % 15-puzzle % % The key predicates are move and in. % Atom move(T,X,Y) has the meaning: at time T tile 0 is moved to % location (X,Y) and % in(T,X,Y,A) is read as: at time T tile A is in location (X,Y). % Initial configuration is given as facts in0(x,y,a). neighbor(X,Y,X+1,Y) :- pos(X), pos(Y), pos(X+1). neighbor(X,Y,X-1,Y) :- pos(X), pos(Y), pos(X-1). neighbor(X,Y,X,Y+1) :- pos(X), pos(Y), pos(Y+1). neighbor(X,Y,X,Y-1) :- pos(X), pos(Y), pos(Y-1). in(0,X,Y,A) :- in0(X,Y,A). goal :- in(T,X,Y,A) : in_t(X,Y,A), time(T), { move(T,X,Y) : move(T,X,Y) } 0. :- not goal. :- move(T,X,Y), not pos(X). :- move(T,X,Y), not pos(Y). :- move(T,X,Y), not time(T). :- move(T,X,Y), maxtime(T). :- move(T,X,Y), { move(T-1,XX,YY) : move(T-1,XX,YY) } 0, T > 0. :- 2 { move(T,X,Y) : move(T,X,Y) }, time(T). :- move(T,X,Y), { in(T,XX,YY,0) : neighbor(XX,YY,X,Y) } 0. in(T+1,X,Y,0) :- move(T,X,Y). in(T+1,X,Y,A) :- in(T,X,Y,0), in(T,XX,YY,A), move(T,XX,YY), neighbor(X,Y,XX,YY), entry(A), A > 0. in(T+1,X,Y,A) :- in(T,X,Y,A), not move(T,X,Y), pos(X), pos(Y), entry(A), A > 0, time(T), maxtime(M), T < M, 1 { move(T,XX,YY) : move(T,XX,YY) }. % Goal configuration % 0 1 2 3 % 4 5 6 7 % 8 9 10 11 % 12 13 14 15 in_t(1,1,0). in_t(1,2,1). in_t(1,3,2). in_t(1,4,3). in_t(2,1,4). in_t(2,2,5). in_t(2,3,6). in_t(2,4,7). in_t(3,1,8). in_t(3,2,9). in_t(3,3,10). in_t(3,4,11). in_t(4,1,12). in_t(4,2,13). in_t(4,3,14). in_t(4,4,15). #hide. #show move(T,X,Y).