prolog MAZE 中没有实现
No implemantation in prolog MAZE
从a到e的迷宫
当我运行get(a,e[a]).
正如我在之前的评论中所说,问题在于 get/3
是 library(pce)
中预定义的谓词。修复代码很简单:
door(a,b).
door(b,c).
door(c,d).
door(d,e).
myget(X,X,A,P) :-
reverse(A,P),
!.
myget(X,Y,A,P) :-
once(door(X,Z);door(Z,X)),
not(member(Z,A)),
format('I am in room ~w.~n', Z),
myget(Z,Y,[Z|A],P).
查询:
?- myget(a,e,[a],P).
I am in room b.
I am in room c.
I am in room d.
I am in room e.
P = [a, b, c, d, e].
从a到e的迷宫
当我运行get(a,e[a]).
正如我在之前的评论中所说,问题在于 get/3
是 library(pce)
中预定义的谓词。修复代码很简单:
door(a,b).
door(b,c).
door(c,d).
door(d,e).
myget(X,X,A,P) :-
reverse(A,P),
!.
myget(X,Y,A,P) :-
once(door(X,Z);door(Z,X)),
not(member(Z,A)),
format('I am in room ~w.~n', Z),
myget(Z,Y,[Z|A],P).
查询:
?- myget(a,e,[a],P).
I am in room b.
I am in room c.
I am in room d.
I am in room e.
P = [a, b, c, d, e].