fork download
  1. :- set_prolog_flag(verbose,silent).
  2. :- prompt(_, '').
  3. :- use_module(library(readutil)).
  4.  
  5.  
  6. % monkey grasps banana
  7. act(state(middle, onbox, middle, hasnot),
  8. grasp,
  9. state(middle, onbox, middle, has) ).
  10.  
  11. % monkey climbs box
  12. act(state(P, onfloor, P, H),
  13. climb,
  14. state(P, onbox, P, H) ).
  15.  
  16. % monkey pushes box from P1 to P2
  17. act(state(P1, onfloor, P1, H),
  18. push(P1, P2),
  19. state(P2, onfloor, P2, H) ).
  20.  
  21. % monkey moves from P1 to P2
  22. act(state(P1, onfloor, B, H),
  23. walk(P1, P2),
  24. state(P2, onfloor, B, H) ).
  25.  
  26. % define (recursively) how the monkey can get the banana
  27. canget(state(_, _, _, has), []).
  28. canget(State1, [State1Action | State2Plan]) :-
  29. act(State1, State1Action, State2),
  30. canget(State2, State2Plan).
  31.  
  32. % define the initial starting condition
  33. go(Plan) :- canget(state(atdoor, onfloor, atwindow, hasnot), Plan), !.
  34.  
  35.  
  36.  
  37. main:-
  38. go(Plan),
  39. write(Plan),
  40.  
  41. :- main.
  42.  
Success #stdin #stdout 0.04s 6288KB
stdin
Standard input is empty
stdout
[walk(atdoor,atwindow),push(atwindow,middle),climb,grasp]