/* Monkey and bananas problem in Picat. Inspired by the Prolog code in Thinking as Computation. This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. % import cp. import bplan. main => go. go => initial_state(Init), % time(bplan(Init,L)), time(plan2(Init,L,Cost)), write(L), nl, writeln(len=L.length), writeln(cost=Cost), nl. % This is the monkey and bananas as a planning problem. % The bananas, monkey, and box are at different locations. % The monkey is not on the box and has no bananas. initial_state(Init) => Init=[loc1,loc2,loc3,n,n]. % The goal is any state where the monkey has the bananas. goal_state(Goal) => Goal=[_,_,_,_,y]. table % Climbing on the box causes the monkey to be on the box. legal_move(From,Move,To,Cost) ?=> From=[B,M,M,n,H],Move=climb_on,To=[B,M,M,y,H],Cost=1. % Climbing off the box causes the monkey to be off the box. legal_move(From,Move,To,Cost) ?=> From=[B,M,M,y,H],Move=climb_off,To=[B,M,M,n,H],Cost=1. % Grabbing the bananas causes the monkey to have the bananas. legal_move(From,Move,To,Cost) ?=> From=[B,B,B,y,n],Move=grab,To=[B,B,B,y,y],Cost=1. % Pushing the box changes where the monkey and the box are. legal_move(From,Move,To,Cost) ?=> From=[B,M,M,n,H],Move=$push(X),To=[B,X,X,n,H],Cost=1. % Going to a location changes where the monkey is. legal_move(From,Move,To,Cost) => From=[B,_,L,n,H],Move=$go(X),To=[B,X,L,n,H],Cost=1.