# Encoding solitare.lparse

Name solitare.lparse [Root]    Unclassified (114) Martin Gebser Copyright Martin Brain 16/10/06, see COPYING for licence 04/08/06 2009-03-30 13:03 2008-11-29 00:10 No % Solitare % % Copyright Martin Brain 16/10/06, see COPYING for licence % 04/08/06 % % 2x2 squares in the corner aren't used location(1,3..5). location(2,3..5). location(3..5,1..7). location(6,3..5). location(7,3..5). % Moves can be made in one of four directions direction(up). direction(down). direction(left). direction(right). % Each location is either full or empty status(full). status(empty). % Note that simply relying on "not status(full)" would give a more ocmpact representation % Can move a full location over a full location to an empty one. possibleMove(T,up,X,Y) :- state(T,full,X,Y), state(T,full,X,Y-1), state(T,empty,X,Y-2), time(T), location(X,Y), location(X,Y-1), location(X,Y-2). possibleMove(T,down,X,Y) :- state(T,full,X,Y), state(T,full,X,Y+1), state(T,empty,X,Y+2), time(T), location(X,Y), location(X,Y+1), location(X,Y+2). possibleMove(T,left,X,Y) :- state(T,full,X,Y), state(T,full,X-1,Y), state(T,empty,X-2,Y), time(T), location(X,Y), location(X-1,Y), location(X-2,Y). possibleMove(T,right,X,Y) :- state(T,full,X,Y), state(T,full,X+1,Y), state(T,empty,X+2,Y), time(T), location(X,Y), location(X+1,Y), location(X+2,Y). % At each time step choose a move 1 { move(T,D,X,Y) : direction(D) : location(X,Y) } 1 :- time(T). % A move must be possible :- move(T,D,X,Y), not possibleMove(T,D,X,Y), time(T), direction(D), location(X,Y). % Now need to look at the effect of moves % (section location parameter to cut grounding size) state(T+1,empty,X,Y) :- move(T,up,X,Y), location(X,Y), time(T). state(T+1,empty,X,Y-1) :- move(T,up,X,Y), location(X,Y), location(X,Y-1), time(T). state(T+1,full,X,Y-2) :- move(T,up,X,Y), location(X,Y), location(X,Y-2), time(T). state(T+1,empty,X,Y) :- move(T,down,X,Y), location(X,Y), time(T). state(T+1,empty,X,Y+1) :- move(T,down,X,Y), location(X,Y), location(X,Y+1), time(T). state(T+1,full,X,Y+2) :- move(T,down,X,Y), location(X,Y), location(X,Y+2), time(T). state(T+1,empty,X,Y) :- move(T,left,X,Y), location(X,Y), time(T). state(T+1,empty,X-1,Y) :- move(T,left,X,Y), location(X,Y), location(X-1,Y), time(T). state(T+1,full,X-2,Y) :- move(T,left,X,Y), location(X,Y), location(X-2,Y), time(T). state(T+1,empty,X,Y) :- move(T,right,X,Y), location(X,Y), time(T). state(T+1,empty,X+1,Y) :- move(T,right,X,Y), location(X,Y), location(X+1,Y), time(T). state(T+1,full,X+2,Y) :- move(T,right,X,Y), location(X,Y), location(X+2,Y), time(T). changed(T+1,X,Y) :- move(T,up,X,Y), location(X,Y), time(T). changed(T+1,X,Y-1) :- move(T,up,X,Y), location(X,Y), location(X,Y-1), time(T). changed(T+1,X,Y-2) :- move(T,up,X,Y), location(X,Y), location(X,Y-2), time(T). changed(T+1,X,Y) :- move(T,down,X,Y), location(X,Y), time(T). changed(T+1,X,Y+1) :- move(T,down,X,Y), location(X,Y), location(X,Y+1), time(T). changed(T+1,X,Y+2) :- move(T,down,X,Y), location(X,Y), location(X,Y+2), time(T). changed(T+1,X,Y) :- move(T,left,X,Y), location(X,Y), time(T). changed(T+1,X-1,Y) :- move(T,left,X,Y), location(X,Y), location(X-1,Y), time(T). changed(T+1,X-2,Y) :- move(T,left,X,Y), location(X,Y), location(X-2,Y), time(T). changed(T+1,X,Y) :- move(T,right,X,Y), location(X,Y), time(T). changed(T+1,X+1,Y) :- move(T,right,X,Y), location(X,Y), location(X+1,Y), time(T). changed(T+1,X+2,Y) :- move(T,right,X,Y), location(X,Y), location(X+2,Y), time(T). state(T+1,S,X,Y) :- not changed(T+1,X,Y), state(T,S,X,Y), status(S), location(X,Y), time(T).