非会员规则未按预期在Prolog中起作用 [英] Not member rule doesn't work as expected in Prolog

查看:70
本文介绍了非会员规则未按预期在Prolog中起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Prolog中创建一个迷宫程序,目的是找到从迷宫的起点到迷宫中心的一个称为m的点的路线.迷宫由正方形组成,这些正方形使用四种颜色之一连接:蓝色,绿色,紫色或橙色.从起点到中心的路线遵循四种颜色的重复图案.

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.

我创建了以下代码:

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?

推荐答案

您定义了changecolour,但从未使用过;您使用了nextcolour,但从未定义它.

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

这篇关于非会员规则未按预期在Prolog中起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆