非成员规则在 Prolog 中无法按预期工作 [英] Not member rule doesn't work as expected in Prolog

查看:16
本文介绍了非成员规则在 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天全站免登陆