两室规划师 Blocks world Prolog

Two room planner Blocks world Prolog

我需要一些非常基本的帮助来解决这个问题。我有一个房间规划器,给定开始状态和结束状态,它使用递归解决这个问题。但是,我想为两个状态(又名房间)解决这个问题。我决定设置标志是我最好的选择,因为房间的每个状态要么在 room1 要么在 room2。但是我不知道如何实现这个。任何人都可以将我推向正确的方向吗?

澄清一下,新状态将是 (ontable(X), room1) 而不是 ontable(X)

:- module( planner,
       [
           plan/4,change_state/3,conditions_met/2,member_state/2,
           move/3,go/2,test/0,test2/0
       ]).

:- [utils].

plan(State, Goal, _, Moves) :-  equal_set(State, Goal),
                write('moves are'), nl,
                reverse_print_stack(Moves).
plan(State, Goal, Been_list, Moves) :-
                move(Name, Preconditions, Actions),
                conditions_met(Preconditions, State),
                change_state(State, Actions, Child_state),
                not(member_state(Child_state, Been_list)),
                stack(Child_state, Been_list, New_been_list),
                stack(Name, Moves, New_moves),
            plan(Child_state, Goal, New_been_list, New_moves),!.

change_state(S, [], S).
change_state(S, [add(P)|T], S_new) :-   change_state(S, T, S2),
                    add_to_set(P, S2, S_new), !.
change_state(S, [del(P)|T], S_new) :-   change_state(S, T, S2),
                    remove_from_set(P, S2, S_new), !.
conditions_met(P, S) :- subset(P, S).

member_state(S, [H|_]) :-   equal_set(S, H).
member_state(S, [_|T]) :-   member_state(S, T).

/* move types */

move(pickup(X), [handempty, clear(X), on(X, Y)],
        [del(handempty), del(clear(X)), del(on(X, Y)),
                 add(clear(Y)), add(holding(X))]).

move(pickup(X), [handempty, clear(X), ontable(X)],
        [del(handempty), del(clear(X)), del(ontable(X)),
                 add(holding(X))]).

move(putdown(X), [holding(X)],
        [del(holding(X)), add(ontable(X)), add(clear(X)),
                  add(handempty)]).

move(stack(X, Y), [holding(X), clear(Y)],
        [del(holding(X)), del(clear(Y)), add(handempty), add(on(X, Y)),
                  add(clear(X))]).

move(goroom1, [handempty], []).
move(goroom1, [holding(X)], []).

move(goroom2, [handempty], []).
move(goroom2, [holding(X)], []).

/* run commands */

go(S, G) :- plan(S, G, [S], []).

test :- go([handempty, ontable(b), ontable(c), on(a, b), clear(c), clear(a)],
              [handempty, ontable(c), on(a,b), on(b, c), clear(a)]).

test2 :- go([handempty, ontable(b), ontable(c), on(a, b), clear(c), clear(a)],
              [handempty, ontable(a), ontable(b), on(c, b), clear(a), clear(c)]).

所以我基本上通过使用标志来解决它。所以对于每个移动谓词,我基本上都添加了一个 room1 和 room2 标志。如果它们为真,则它会执行操作。因此,例如 room1 中的 ontable(X),然后删除 ontable 并在 room1 中添加 holding(X)。我还添加了两个谓词以在房间之间移动。最大的障碍是从过程逻辑转向状态逻辑。所以如果 handempty 在 room1 那么它只能移动到 room2! @CapelliC 谢谢你的建议