在Prolog中收集回溯解决方案



我在收集Swi-prolog中回溯的解决方案时遇到了麻烦,所以我的代码是:

fxd_cell(1,1,2).
fxd_cell(1,3,7).
fxd_cell(1,4,3).
fxd_cell(1,6,1).
fxd_cell(1,8,8).
fxd_cell(2,2,5).
fxd_cell(2,4,6).
fxd_cell(2,5,2).
fxd_cell(2,6,9).
fxd_cell(2,9,4).
fxd_cell(3,1,3).
fxd_cell(3,2,6).
fxd_cell(3,3,9).
fxd_cell(3,6,4).
% snip
fxd_cell(9,7,4).
fxd_cell(9,9,2).

index(_,_).
get_num(X) :- L=[1,2,3,4,5,6,7,8,9], member(X,L).
isEmpty([]):- 1 = 1.
isEmpty([H|_]):- + get_num(H),!.
find_Empty(L):-  fail .
find_Empty(L):- get_num(X),get_num(Y),findall(Num,fxd_cell(X,Y,Num),L1),isEmpty(L1),L=        [index(X,Y)|LL].

当我调用find_Empty(L)结果将显示为:

L = [index(1, 2)|_G3978] 

,当我按";"时,另一个解决方案,如:

L = [index(1, 5)|_G3978] ;
L = [index(1, 7)|_G3978] 

显示…但是我想让L包含所有的解怎么做呢?

使用findall/3:

findall(X, find_Empty(X), L).

最新更新