Perseverance
Perseverance

Reputation: 345

Prolog restrictions - puzzle

I'm developing a game named woodntDie. This game consists in 9 pieces which should look like this:

enter image description here

The aim is to arrange all those pieces and make it look like a dice:

enter image description here

This is the four final possible solutions with all those 9 pieces.

I'm trying to implement some restrictions but those arent enough:

sum([V5, V6, V11, V12, V17, V18, V23, V24, V29, V30, V35, V36, V41, V42,  V47, V48, V53, V54], #=, 7),

The sum of the opposite faces should always be 7. In this restriction I'm telling that the sum of the top and bottom face it's 7.

sum([V2, V19, V7, V16, V31, V26], #=, 7),

The sum of the front and back faces is 7 aswell.

sum([V1, V49, V13, V8, V37, V25], #=, 7),

The sum of the left and right face is 7.

sum(Vars, #=, 21),

The sum of all the dots it's 21.

But I'm getting a really weird output, I'm getting repeated pieces and a load of solutions that doesnt make any sense and dont form a dice at all. I think I need few more restrictions and my questions are:

How do I make a restrictions saying that some pieces cant be repeated (notice that I can have two F pieces but all the other ones cant be similar)

How do I make a new restriction with this:

The only other remaining bar to have two spots on its side is C, so C must combine with A to make the 4 or 5 face

The only other bar to have a spot on its side near one end is E, so E must combine with B to make the 2 or 3 face.

I mean, is there any way to say "the sum of VX, VY, VZ it's 2 or 3".

And do you have any other opinion that would make the solution easier?

I'm struggling here and I really dont know what to do, I'd really appreciate all the help I could get.

Here's the whole code:

:-use_module(library(clpfd)).
:-use_module(library(lists)).

dice(Vars):-
Vars=[V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15, V16, V17, V18,
  V19, V20, V21, V22, V23, V24, V25, V26, V27, V28, V29, V30, V31, V32, V33, V34, V35, V36,
  V37, V38, V39, V40, V41, V42, V43, V44, V45, V46, V47, V48, V49, V50, V51, V52, V53, V54],
% pecas dos topos
domain([V5, V6, V11, V12, V17, V18, V23, V24, V29, V30, V35, V36, V41, V42,  V47, V48, V53, V54], 0, 1),
% pecas laterais
domain([V1, V2, V3, V4, V7, V8, V9, V10, V13, V14, V15, V16, V19, V20, V21, V22, V25, V26, V27, V28,
    V31, V32, V33, V34, V37, V38, V39, V40, V43, V44, V45, V46, V49, V50, V51, V52], 0,2),
table([
[V1, V2, V3, V4, V5, V6], %%peca1
[V7, V8, V9, V10, V11, V12], %%peca2
[V13, V14, V15, V16, V17, V18], %%peca3
[V19, V20, V21, V22, V23, V24], %%peca4
[V25, V26, V27, V28, V29, V30], %%peca5
[V31, V32, V33, V34, V35, V36], %%peca6
[V37, V38, V39, V40, V41, V42], %%peca7
[V43, V44, V45, V46, V47, V48], %%peca8
[V49, V50, V51, V52, V53, V54]], %%peca9
          
  [[2,2,0,0,1,0], %%peca1
   [2,1,0,0,1,1], %%peca2
   [2,0,0,0,1,1], %%peca3
   [2,0,0,0,0,0], %%peca4
   [1,0,0,0,1,0], %%peca5
   [1,0,0,0,0,0], %%peca6
   [1,0,0,0,0,0], %%peca7
   [0,0,0,0,1,0], %%peca8
   [0,0,0,0,0,0]]), %%peca9

% restricoes para as faces que envolve os topos de cada peça
% Na figura de descriçºao das peças os topos de cima estão guardados 
% na posicao 5 de cada lista. Os topos de baixo estoa guardados na
% posicao 6 de cada lista


   % Restrições quanto à soma de faces opostas(=7)

V2 + V19 + V7 #= TotalF1,
    
V8 + V37 + V25 #= TotalF2,

V5 + V23 + V11 + V53 + V47 + V41 + V29 + V35 + V17 #= TotalF3,

V18 + V36 + V30 + V54 + V48 + V42 + V6 + V24 + V12 #= TotalF4,

V1 + V49 + V13 #= TotalF5,

V16+ V31 + V26 #= TotalF6,

Totals = [TotalF1, TotalF2, TotalF3, TotalF4, TotalF5, TotalF6],

domain(Totals, 1,6),

all_different(Totals),

TotalF3 + TotalF4 #= 7,
TotalF1 + TotalF6 #= 7,
TotalF5 + TotalF2 #= 7,

A #= 100000*V1 + 10000*V2+ 1000*V5, 
element(P1,Vars,A),

B #= 100000*V7 + 10000*V8 + 10*V11 + V12,
element(P2,Vars,B),

C #= 100000*V13 + 10*V17 + V18,
element(P3,Vars,C),

D #= 100000*V19,
element(P4,Vars,D),

E #= 100000*V25 + 10*V29,
element(P5,Vars,E),

F #= 100000*V31,
element(P6,Vars,F),

G #= 100000*V37,
element(P7,Vars,G),

H #= 100*V47,
element(P8,Vars,H),

I #= 0,
element(P9,Vars,I),

F#=P7,
F#=G,

PiecesIndex = [P1, P2, P3, P4, P5, P6, P8, P9],

all_different(PiecesIndex),


%There are 21 spots on the pieces
%sum(Vars, #=, 21),




labeling([],Vars),
show(Vars).


    
show([V1, V2, V3, V4, V5, V6, V7, V8, V9, V10, V11, V12, V13, V14, V15, V16, V17, V18,
  V19, V20, V21, V22, V23, V24, V25, V26, V27, V28, V29, V30, V31, V32, V33, V34, V35, V36,
  V37, V38, V39, V40, V41, V42, V43, V44, V45, V46, V47, V48, V49, V50, V51, V52, V53, V54]) :-
write([V1, V2, V3, V4, V5, V6]), nl, 
write([V7, V8, V9, V10, V11, V12]), nl, 
write([V13, V14, V15, V16, V17, V18]), nl, 
write([V19, V20, V21, V22, V23, V24]), nl, 
write([V25, V26, V27, V28, V29, V30]), nl, 
write([V31, V32, V33, V34, V35, V36]), nl, 
write([V37, V38, V39, V40, V41, V42]), nl, 
write([V43, V44, V45, V46, V47, V48]), nl, 
write([V49, V50, V51, V52, V53, V54]), nl. 

and here's a pic with the representation of the dice and all those V's (each V represents the dots on each face)

enter image description here

ALL THE INFORMATION ABOUT THE GAME

Thank you so much in advance

Any doubt just ask or add me on skype: preserverance

Best regards

Upvotes: 2

Views: 228

Answers (1)

Topological Sort
Topological Sort

Reputation: 2787

I mean, is there any way to say "the sum of VX, VY, VZ it's 2 or 3".

If this is the crucial question, try this:

(sum([VX,VY,VZ],#=,2);sum([VX,VY,VZ],#=,3))

Upvotes: 1

Related Questions