我已经定义了房间门的列表:
class facts
door : (string Room1, string Room2).
skarb : (string Skarb, string Room).
class predicates
go : (string Room1, string Room2, string* R_list) nondeterm anyflow.
is_Member : (string Room, string* R_list) nondeterm .
write_list : (string* R_list) nondeterm .
clauses
door("a", "b").
door("b", "e").
door("b", "c").
door("d", "e").
door("c", "d").
door("e", "f").
door("g", "e").
door("g", "a").
door("h", "b").
door("h", "a").
door("h", "f").
door("i", "b").
door("i", "h").
door("i", "c").
door("i", "k").
skarb("bomba", "d").
还有一些谓词:
go(Room, Room, R_list) :- stdio::write("\n\nJest droga:"), write_list(R_list), !.
go(Room1, Room2, R_list) :- door(Room1, X), not(is_Member(X, R_list)), go(X, Room2, [X | R_list]).
go(Room1, Room2, R_list) :- door(X, Room1), not(is_Member(X, R_list)), go(Room2, X, [X | R_list]).
is_Member(Room, [Room | _]) :- !. is_Member(Room, [_ | Tail]) :- is_Member(Room, Tail).
write_list([]) :- !.
write_list([Head | Tail]) :- stdio::write( Head), write_list(Tail).
我正在寻找从一个房间到另一个房间的方法:
run():-
stdio::write("\nDroga z a do f"),
R_list=["a"],
go("a", "f", R_list),
fail.
此谓词有效并返回:
Jest droga:feba
Jest droga:fedcba
这是房间列表,我必须将其从 a 传递到 f。run():- stdio::write("\nDroga zf do a"), R_list=["f"], go("f", "a", R_list), 失败。但是这个,一无所获。而且您可能会注意到,这与前一种情况正好相反。