Prolog 路径重复次数超过特定数量

Prolog 路径重复次数超过特定数量,prolog,Prolog,共有8间客房,具体为a房、b房、c房、d房、e房、f房、g房、h房。问题是,它向我展示了一个平局,并要求我房间的每扇门不应超过4扇。这个代码应该是什么?我所做的是: %the directions next_to(a,b). next_to(a,c). next_to(a,d) next_to(b,a). next_to(b,h). next_to(c,a). next_to(c,d). next_to(d,a). nex

共有8间客房,具体为a房、b房、c房、d房、e房、f房、g房、h房。问题是,它向我展示了一个平局,并要求我房间的每扇门不应超过4扇。这个代码应该是什么?我所做的是:

 %the directions
    next_to(a,b).
    next_to(a,c).
    next_to(a,d)
    next_to(b,a).
    next_to(b,h).
    next_to(c,a).
    next_to(c,d).
    next_to(d,a).
    next_to(d,c).
    next_to(d,f).
    next_to(e,d).
    next_to(e,g).
    next_to(h,b).
    next_to(h,g).
    next_to(g,e).
    next_to(g,h).
    next_to(g,f).
    next_to(f,d).
    next_to(f,g).
    %i did for two ,i mean not to repeated more than 2 times, but the exercise asking me no more than 4
   %i did a loop here smaller than 4 ,i know its wrong.
    calc(L, NL):-
      include(in_range, L, NL).

    pathloop(Start, End, _, [Start, End]) :-
        next_to(Start, End).
    pathloop(Start, End, Visited, [Start|PathRest]) :-
        next_to(Start, Second),
        not(member(Second, Visited)),
        pathloop(Second, End, [Second|Visited], PathRest).



    in_range(X):-
      number(X),
      (X > 0 ; X < 4)
%
(a,b)的下一步。
接(a,c)。
(a,d)的下一个
接(b,a)。
其次是(b,h)。
接(c,a)。
(c,d)的下一个。
接(d,a)。
接(d,c)。
(d,f)的下一个。
接(e,d)。
下一个到(例如,g)。
接(h,b)。
紧挨着(h,g)。
接(g,e)。
其次是(g,h)。
紧挨着(g,f)。
(f,d)的下一个。
紧挨着(f,g)。
%我做了两次,我的意思是不要重复超过2次,但练习要求我不要超过4次
%我在这里做了一个小于4的循环,我知道它错了。
计算(L,NL):-
包括(在_范围内,L,NL)。
pathloop(开始,结束,u[开始,结束]):-
下一步(开始、结束)。
pathloop(开始、结束、访问,[Start | PathRest]):-
下一步(开始,秒),
非(成员(第二,访问)),
pathloop(第二,结束,[第二次访问],PathRest)。
在_范围内(X):-
编号(X),
(X>0;X<4)

.

我不知道
calc
如何与您的
pathloop
谓词相匹配。我编辑了可能会更好