I'm learning Prolog and I'm writing STRIPS algorithm. Exactly I try to write it because it doesn’t work and unfortunately, I can't understand why. Simply, the program doesn't stop, it thinks what kind is next action but doesn't apply it. Below, I post a code of my program, I hope that there will be somebody with more experience could put me in right direction. May be the recursion is wrong but I can't find a mistakes. Thank you!
The plan/2 and action/4 are predicate written in world representation file.
strips(Plan):-
[worldblock_rap],
plan(Initstate,Goallist),
strip1(Initstate,Goallist,RevPlan,[]),
reverse(RevPlan, Plan).
%strips(+GoalList, +State, +Plan, +ForbiddenActions
strip1(State,Goallist,_,_):-
there_is(State, Goallist).
%strips(+GoalList, +State, +Plan, +ForbiddenActions
strip1(State,Goallist,Plan,ForibiddenActions):-
%*****choose the right action******
action(Ac,Prec,Del,Add),
there_is(Goal, Goallist),
\+there_is(Goal, State),
there_is(Add,Goal),
\+belongs(Ac,ForibiddenActions),
%*****************
%******achive its precondition*******
strip1(TmpState1,Prec,TmpPlan1,[Ac| ForibiddenActions]),
%********************************
%***********Update the new plan with precondition's subplan and this action
apply_rule(Ac,Del,Add,TmpState1,NewState),
append([Ac|TmpPlan1], Plan, NewPlan),
strip1(NewState,Goallist,NewPlan,[Ac|ForibiddenActions]).
apply_rule(Ac,Dellist,Addlist,State,NewState):-
nl,write("doing"), write(Ac), ttyflush,
delete_list(State, Dellist,TmpState),
append(Addlist,TmpState,NewState).
reverse([],A,A).
reverse([X|L],L1,A):-reverse(L,[X|L1],A).
delete_list([H|T], List, Final):-
remove(H, List, Tmp),
delete_list(T, Tmp, Final).
delete_list([], List, List).
remove(X, [X|T], T).
remove(X, [H|T], [H|R]):-
remove(X, T, R).
append([H|T], L1, [H|L2]):-
append(T, L1, L2).
append([], L, L).
belongs(X, [X|_]).
belongs(X, [_|T]):-
belongs(X, T).
there_is([], _).
there_is([X|T], L):-
belongs(X, L),
there_is(T, L).