Skip to content

Instantly share code, notes, and snippets.

@aman-tiwari
Last active November 16, 2017 00:45
Show Gist options
  • Save aman-tiwari/4992194b7d2d31b6fcfea353863346cd to your computer and use it in GitHub Desktop.
Save aman-tiwari/4992194b7d2d31b6fcfea353863346cd to your computer and use it in GitHub Desktop.
wfc in clingo?
% Default
#const n = 5.
% define?
cell(1..n, 1..n).
pattern(a).
pattern(b).
dx(0, 1).
dx(1, 0).
dx(I, J) :- dx(-I, -J).
legal(0, 0, P, P) :- pattern(P).
legal(0, 1, a, b).
legal(0, 1, b, a).
legal(1, 0, a, b).
legal(1, 0, b, a).
legal(DX, DY, P1, P2) :- legal(-DX, -DY, P2, P1).
adj(X1, Y1, X2, Y2, DX, DY) :-
assign(X1, Y1, P1), assign(X2, Y2, P2),
dx(DX, DY), |X1 - X2|==DX, |Y1 - Y2|==DY.
% generate?
1 { assign(X,Y,P):pattern(P) } 1 :- cell(X,Y).
% constraint?
:- adj(X1,Y1,X2,Y2,DX,DY), assign(X1,Y1,P1),
not 1 { assign(X2,Y2,P2):legal(DX,DY,P1,P2) }.
#show assign/3.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment