% holds_in(Goal,State) is true if Goal is true in State.
holds_in(true,State).
holds_in(A & B, State) <-
   holds_in(A, State) &
   holds_in(B,State).
holds_in(H,State) <-
   (H <= B) &
   holds_in(B,State).
holds_in(A \= B,S) <-
   A \= B.
holds_in(G,init) <-
   primitive(G) &
   holds(G,init).
holds_in(G,do(A,S)) <-
   primitive(G) &
   addlist(A,AL) &
   member(G,AL) &
   preconditions(A,AP) &
   holds_in(AP,S).
holds_in(G,do(A,S)) <-
   primitive(G) &
   holds_in(G,S) &
   preconditions(A,AP) &
   holds_in(AP,S) &
   deletelist(A,DL) &
   notin(G,DL).

% member(E,L) is true if E is a member of list L
member(E,[E|R]).
member(E,[H|R]) <-
   member(E,R).

% notin(E,L) is true if E is not a member of list L
notin(E,[]).
notin(E,[H|R]) <-
   E \= H &
   notin(E,R).


% TRY THE FOLLOWING QUERIES with delrob_strips.pl:
% bound 13.     %% this sets the depth-bound
% ask holds_in(carrying(rob,k1),do(pickup(rob,k1,mail),do(move(rob,o103,mail),do(move(rob,o109,o103),init))) ).
% ask holds_in(carrying(rob,k1),S ).

% bound 31.
% ask holds_in(at(k1,lab2),do(move(rob,o103,lab2),do(unlock(rob,door1),do(move(rob,mail,o103),do(pickup(rob,k1,mail),do(move(rob,o103,mail),do(move(rob,o109,o103),init)))))) ).
%  try increasing the depth bound to 32.
% ask holds_in(at(k1,lab2),S ).


% ask holds_in(carrying(rob,parcel)& sitting_at(rob,lab2),do(move(rob,o103,lab2),do(unlock(rob,door1),do(move(rob,mail,o103),do(pickup(rob,k1,mail),do(move(rob,o103,mail),do(move(rob,o109,o103),do(move(rob,storage,o109),do(pickup(rob,parcel,storage),do(move(rob,o109,storage),init)))))))))    ).

% ask holds_in(carrying(rob,parcel)& sitting_at(rob,lab2),S).

%%% load 'c:/david/teach/cs322/1999/Module10/back_strips.pl'.
%%% load 'c:/david/teach/cs322/1999/Module10/delrob_strips.pl'.

