# Encoding solitaire.enc.asp

Name solitaire.enc.asp [Root]    Unclassified (114) Barbara Nardi Yuliya Lierler and Marcello Balduccini 2012-04-12 11:28 2012-04-12 11:28 No %The configuration at time 0 photo(0,1,C,R) :- full(C,R). photo(0,0,C,R) :- empty(C,R). inv(0,1). inv(1,0). %ALL legal moves at time T+1 move_all(T1,down,C,R) :- photo(T,1,C,R), R1=R+1, photo(T,1,C,R1), R2=R+2, photo(T,0,C,R2), T1=T+1, time(T1). move_all(T1,up,C,R) :- photo(T,1,C,R), R1=R-1, photo(T,1,C,R1), R2=R-2, photo(T,0,C,R2), T1=T+1, time(T1). move_all(T1,left,C,R) :- photo(T,1,C,R), C1=C-1, photo(T,1,C1,R), C2=C-2, photo(T,0,C2,R), T1=T+1, time(T1). move_all(T1,right,C,R) :- photo(T,1,C,R), C1=C+1, photo(T,1,C1,R), C2=C+2, photo(T,0,C2,R), T1=T+1, time(T1). %GUESS a set of legal MOVES move(T,D,C,R) | notMove(T,D,C,R) :- move_all(T,D,C,R). %ONLY one move for each step (time) is allowed :- move(T,D1,Fv1,Fv2), move(T,D2,Fv3,Fv4), D1 <> D2. :- move(T,Fv1,C1,Fv2), move(T,Fv3,C2,Fv4), C1 <> C2. :- move(T,Fv1,Fv2,R1), move(T,Fv3,Fv4,R2), R1 <> R2. moveT(T) :- move(T,Fv1,Fv2,Fv3). :- time(T), not moveT(T). %The cells changed after the move down at time T changed(T,0,C,R) :- move(T,down,C,R). changed(T,0,C,R1) :- move(T,down,C,R), R1=R+1. changed(T,1,C,R2) :- move(T,down,C,R), R2=R+2. %The cells changed after the move up at time T changed(T,0,C,R) :- move(T,up,C,R). changed(T,0,C,R1) :- move(T,up,C,R), R1=R-1. changed(T,1,C,R2) :- move(T,up,C,R), R2=R-2. %The cells changed after the move left at time T changed(T,0,C,R) :- move(T,left,C,R). changed(T,0,C1,R) :- move(T,left,C,R), C1=C-1. changed(T,1,C2,R) :- move(T,left,C,R), C2=C-2. %The cells changed after the move right at time T changed(T,0,C,R) :- move(T,right,C,R). changed(T,0,C1,R) :- move(T,right,C,R), C1=C+1. changed(T,1,C2,R) :- move(T,right,C,R), C2=C+2. %The configuration at time T (after the ONLY move at time T) photo(T1,S,C,R) :- photo(T,S,C,R), T1=T+1, time(T1), inv(S,SI), not changed(T1,SI,C,R). photo(T,S,C,R) :- changed(T,S,C,R).