-1

The dog can perform the following actions: walk on floor; climb the box (if it is already at the box); and grasp the meat if standing on the box directly under the meat. but when i run the code below but i get an Error

procedure `(A:-B)' does not exist Reachable from:
swish_trace:swish_call((start:-canget(state(atdoor,onfloor,atwindow,hasmeat)))) '$swish wrapper'((start:-canget(state(atdoor,onfloor,atwindow,hasmeat))),A)

    move(state(middle,onbox,middle,has_no_meat),state(middle,onbox,middle,has_meat)).
/*climbing the box*/

 move(state(middle_floor, onfloor, middle_floor,has_no_meat), climb,

  state(middle_floor,onbox, middle_floor,has_meat)).

 /*pushing the box to the middle of the room*/

 move(state(atwindow,onfloor,atwindow,has_box),      
 push(atwindow,middle_floor),

 state(middle_floor,onfloor,middle_floor,has_box)).

 /*dog walks from the door to the window*/

   move(state(atdoor,onfloor,box,has_not), walk(atdoor,atwindow),

   state(atwindow,onfloor,box,has_box)).

   canget(state(_, _, _, has_meat)).

   canget(State1) :- move(State1, Move, State2), canget(State2).

1 Answers1

0

I don't undertand exactly what do you want to do but...

1) according the error message, if I understand correctly, you're trying to validate the goal

canget(state(atdoor,onfloor,atwindow,hasmeat))

so using hasmeat instead of has_meat

2) using has_meat, the goal is immediatly true thanks to the fact

canget(state(_, _, _, has_meat))

so I suppose that your starting fact should be something with has_no_meat

3) You're first move is a move/2 (a couple of states) instead move/3 (state, action, state); I suggest to add an action; something like

move(state(middle,onbox,middle,has_no_meat),
     take_meat,
     state(middle,onbox,middle,has_meat)).

4) In the following canget rule

 canget(State1) :- move(State1, Move, State2), canget(State2).

Move is a singleton variable; if you dont use it (write(Move)?) it's only a source of disturbing warnings; I suggest to rewrite it as

canget(State1) :-
   move(State1, _, State2),
   canget(State2).
max66
  • 65,235
  • 10
  • 71
  • 111