Not member rule doesn't work as expected in Prolog

那年仲夏 提交于 2019-12-02 18:11:50

问题


I am attempting to create a maze program in Prolog, whereby the aim is to find a route from the start of the maze to a point in the centre of the maze called m. The maze consists of squares which are connected using one of four colours: Blue, Green, Purple or Orange. The route from start to the centre follows a repeating pattern of the four colours.

I have created the following code:

link2(A, Colour, B) :- link(A, Colour, B).       
link2(A, Colour, B) :- link(B, Colour, A).

changecolour(blue,green).
changecolour(green,purple).
changecolour(purple,orange).
changecolour(orange,blue).

route(A, Colour1, B, List2) :-
    link2(A, Colour1, B),
    append([A], [B], List2).
route(A, Colour1, B, List2) :-
    link2(A, Colour1, X),
    changecolour(Colour1,Colour2),
    append([A], List, List2),
    \+ member(A, List),
    route(X, Colour2, B, List).

For some reason, the code isn't working as expected and I'm not sure why. I have a feeling its something to do with the negation(not member) rule but can someone advise what I'm doing wrong?


回答1:


You defined changecolour and never used it; you used nextcolour but never defined it.



来源:https://stackoverflow.com/questions/36866460/not-member-rule-doesnt-work-as-expected-in-prolog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!