I'm developing a PROLOG program with restrictions to find the solutions for a certain game.
Question#1: For debugging purposes, I want to count the number of possible solutions of the game. Is there any way to do this via the labeling/2
predicate?
My goal is to count the number of possible combinations between the cubes (Instant Insanity):
insanity2(Vars) :-
Vars = [F1,B1,R1,L1,U1,D1,
F2,B2,R2,L2,U2,D2,
F3,B3,R3,L3,U3,D3,
F4,B4,R4,L4,U4,D4],
/* Colors range (4 colors) */
domain(Vars, 1,4),
/* Restrictions */
%Color restrictions
% Cube #1
alocCubeColors(F1,B1,R1,L1,U1,D1),
% Cube #2
alocCubeColors(F2,B2,R2,L2,U2,D2),
% Cube #3
alocCubeColors(F3,B3,R3,L3,U3,D3),
% Cube #4
alocCubeColors(F4,B4,R4,L4,U4,D4),
%Logic restrictions
F1#\=F2, F1#\=F3, F1#\=F4, F2#\=F3, F2#\=F4, F3#\=F4,
B1#\=B2, B1#\=B3, B1#\=B4, B2#\=B3, B2#\=B4, B3#\=B4,
R1#\=R2, R1#\=R3, R1#\=R4, R2#\=R3, R2#\=R4, R3#\=R4,
L1#\=L2, L1#\=L3, L1#\=L4, L2#\=L3, L2#\=L4, L3#\=L4,
labeling([], Vars).
Question#2: Is it possible to manipulate labeling/2
output, in order to rearranje it in a proper way?
For your question #1 you can use the findall/3
predicate:
Ex:
| ?- X=[X1,X2], domain(X,0,2), findall(X, labeling([],X), Xl ), length(Xl,L).
X = [X1,X2],
Xl = [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]],
L = 9,
X1 in 0..2,
X2 in 0..2 ?
yes
| ?-