% Sate representation, use a functor state/4 % state(Monkey_horiz_pos, Monkey_vert_pos, Box_pos, Has_banana) % To generate actions which change state use move/3 % move(CurrentSate, Action, NewState) % Four possible actions: walk, climb, push, grasp % grasp banana move(state(middle,onbox,middle,hasnot), grasp, state(middle,onbox,middle,has)). % climb move(state(P,onfloor,P,H), climb, state(P,onbox,P,H)). % push box move(state(P1,onfloor,P1,H), push(P1,P2), state(P2,onfloor,P2,H)). % walk move(state(P1,onfloor,B,H), walk(P1,P2), state(P2,onfloor,B,H)). % recursive "depth first search" predicate canget(State) % which tells you if a solution is possible from State canget(state(_, _, _, has)). canget(State1) :- move(State1, Action, State2), showAction(State1, Action, State2), canget(State2). % this predicate is just to show the step by step moves that Prolog % tries as it blindly tries to find a path thruough the search % space, including backtracking when it reaches a cul de sac. showAction(S1, A, S2) :- nl, write(S1), write(' -> '), write(A), write( ' -> '), write(S2), nl, write(' press c to continue '), read(P).