我们正在编写一个Prolog程序来解决逻辑益智游戏。我们已经创建了所有值,但是似乎要在程序中应用的规则不起作用。我们得到了所有可能的结果,而不是正确的答案。也可能是一些语法错误或符号错误,请同时指出。
riders([50,
75,
100,
125,
150]).
employees([chris,
eduardo,
guy,
kurt,
sergio]).
sections([blue,
green,
orange,
purple,
yellow]).
rides([ agony-alley, doop-d-doop, the-breaker, the-screamer, zinjo]).
% Of the worker who works in the orange section and Sergio,
% one served 125 riders and the other manages TheBreaker
rule1(c,n,r,m):- (c=orange ,r=125
;n = serigo, m = the-breaker
;n = serigo, r = 125
;c = orange, m = the-reaker
;n\=serigo, r\=125, c\=orange, b\=the-breaker
).
%Eduardo is either the employee who manages The Breaker or the employee who
served 100 riders..
rule2(n,m,r) :- (n = eduardo, m = the-breaker
;n = eduardo, r = 100
;n\= eduardo, m\= the-breaker, r\= 100).
% Sergio served 50 riders..
rule3(n,r) :- (n= sergio, r = 50).
% The person who served 150 riders is either the employee who works in the
blue section or Kurt..
rule4(n,c,r) :- ( r= 150, n = kurt
;r = 150, c = blue
;r\= 150, n\= kurt ,c\= blue).
rule5(n, c, r, m) :- (n = kurt, c = yellow
;n = kurt, m = the-breaker
;r = 100, c = yellow
;r = 100, m =the-breaker
;n\=kurt, r\=100, c\=yellow, m\=the-breaker).
rule6(r, m) :- not((r = 125, m = loop-d-loop)).
rule7(n,r,m) :- ( n = guy, r = r
; m = the-breaker, r = r + 50).
rule8(m, c) :- not((m = zinjo, c = orange)).
rule9(n, c) :- not((n = sergio, c = orange)).
% Of the worker who manages Loop-D-Loop and the worker who served 75 riders,
% one is Chris and the other works inthe green section..
rules10(m,r,n,c) :-( r = 75,n = chris
;m = loop-d-loop,c = green
;r = 75,c = green
;m = loop-d-loop,n = chris
;r\= 75,n\= chris, m\= loop-d-loop,c\= green).
solution(X) :-
riders(Riders),
employees(Names),
sections(Colors),
rides(Managers),
% Generate all possible solutions
% (brute force)
[R1, R2, R3, R4, R5] = Riders,
permutation([N1, N2, N3, N4, N5], Names),
permutation([C1, C2, C3, C4, C5], Colors),
permutation([M1, M2, M3, M4, M5], Managers),
% Format the variables as solutions table
X = [[R1, N1, C1, M1],
[R2, N2, C2, M2],
[R3, N3, C3, M3],
[R4, N4, C4, M4],
[R5, N5, C5, M5]],
% Check the constraints from the puzzle
forall(member([r,n,c,m], X),
rule1(c,n,r,m)),
% rule2
forall(member([r,n,_,m], X),
rule2(n,m,r)),
% rule 3
forall(member([r,n,_,_], X),
rule3(n,r)),
% Rule 4
forall(member([r, n, c, _], X),
rule4(n,c,r)),
forall(member([r,n,c,m], X),
rule5(n, c, r, m)),
forall(member([r,_,_,m], X),
rule6(r, m)),
forall(member([r,n,_,m], X),
rule7(n,r,m)),
forall(member([r,n,c,m], X),
rule8(m, c)),
forall(member([r,n,c,m], X),
rule9(n, c)),
forall(member([r,n,c,m], X),
rules10(m,r,n,c)).
这是代码。谁能帮助解决这个问题?