Attachment 'Connected-Maximum-density-Still-Life-ENCODING.txt'
Download 1 % possible coordinates
2 value(0).
3 value(V) :- value(V1), V=V1+1, size(N), V1<=N.
4
5 step(-1).
6 step(1).
7 diff(X,0) :- step(X).
8 diff(0,Y) :- step(Y).
9 diff(X,Y) :- step(X), step(Y).
10
11 % a cell may live, except for the ones at the border
12 { lives(X,Y) } <= 1 :- value(X), value(Y), X>0, Y>0, size(N), X<=N, Y<=N.
13
14 % cells with exactly 3 neighbours must live
15 :- #sum { 1 : lives(X+DX,Y+DY), diff(DX,DY) } = 3, not lives(X,Y), value(X), value(Y).
16
17 % living cells must have 2-3 living neighbours
18 :- lives(X,Y), not 2 <= #sum { 1 : lives(X+DX,Y+DY), diff(DX,DY) } <= 3, value(X), value(Y).
19
20 % connectedness
21 reached(XX,YY) :- XX = #min { X : lives(X,Y), value(X), value(Y) }, YY = #min { Y : lives(XX,Y), value(Y) }.
22 reached(XX,YY) :- reached(X,Y), value(X), value(Y), diff(DX,DY), XX=X+DX, YY=Y+DY, lives(XX,YY).
23 :- lives(X,Y), not reached(X,Y), value(X), value(Y).
24
25 % maximise living cells
26 %#maximise { 1 : lives(X,Y), value(X), value(Y) }.
27 :~ value(X),value(Y), not lives(X,Y).
Attached Files
You are not allowed to attach a file to this page.