%/* Monkey and the banana problem Robert Klerer */ %/* */ % solve(Time, Actions, States)? Generates possible plans... solve(0,[],[state(a,c,d,couch,nil)]). solve(T1,[A; H],[X,Y; Z]) :- solve(T0,H,[Y; Z]) , rule(A,Y,X) , not member(X,[Y; Z]) , T1 is T0+1. rule(get_off(couch),state(a,W,X,couch,Y),state(a,W,X,floor,Y)). rule(get_off(chair),state(W,W,X,chair,Y),state(W,W,X,floor,Y)). rule(get_on(chair),state(W,W,X,floor,Y),state(W,W,X,chair,Y)). rule(get_on(couch),state(a,W,X,floor,Y),state(a,W,X,couch,Y)). rule(move(self,a),state(W,X,Y,floor,nil),state(a,X,Y,floor,nil)). rule(move(self,b),state(W,X,Y,floor,nil),state(b,X,Y,floor,nil)). rule(move(self,c),state(W,X,Y,floor,nil),state(c,X,Y,floor,nil)). rule(move(self,d),state(W,X,Y,floor,nil),state(d,X,Y,floor,nil)). rule(move(stick,a),state(W,X,W,floor,stick),state(a,X,a,floor,stick)). rule(move(stick,b),state(W,X,W,floor,stick),state(b,X,b,floor,stick)). rule(move(stick,c),state(W,X,W,floor,stick),state(c,X,c,floor,stick)). rule(move(stick,d),state(W,X,W,floor,stick),state(d,X,d,floor,stick)). rule(move(chair,a),state(W,W,X,floor,nil),state(a,a,X,floor,nil)). rule(move(chair,b),state(W,W,X,floor,nil),state(b,b,X,floor,nil)). rule(move(chair,c),state(W,W,X,floor,nil),state(c,c,X,floor,nil)). rule(move(chair,d),state(W,W,X,floor,nil),state(d,d,X,floor,nil)). rule(grasp(stick),state(W,X,W,floor,nil),state(W,X,W,floor,stick)). rule(drop(stick),state(W,X,W,floor,stick),state(W,X,W,floor,nil)). rule(grasp(banana),state(b,X,Y,chair,stick),state(b,X,Y,chair,banana)). :- write('Monkey and banana loaded!'), nl. :-listing.