Commit c0887701 authored by Sergey Kireev's avatar Sergey Kireev
Browse files

sqr8 find_groups implemented in processing

parent 04cbf2ee
...@@ -989,21 +989,6 @@ class NLE_squ4_CA extends NLE_CA { ...@@ -989,21 +989,6 @@ class NLE_squ4_CA extends NLE_CA {
return count; return count;
} }
/* float count_dH_move_NL(int bx,int by,int dir) {
float dH = 0;
for (int i=0;i<st[dir].length;i++) {
int state = state_clear_id(getfix(bx + ctx[dir][i],by + cty[dir][i]));
if (state == st[dir][i]) {
dH += dh[i];
//!print(" [",ctx[dir][i],cty[dir][i],"]=");
//!if (isL(state)) print("L: ");
//!if (isN(state)) print("N(",s2x(state),s2y(state),"): ");
//!println(dh[i]);
}
}
return dH;
}*/
void do_move_NL(int bx,int by,int dir) { void do_move_NL(int bx,int by,int dir) {
XY nb = new XY(bx,by); XY nb = new XY(bx,by);
int id = s2id(getfix(bx,by)); int id = s2id(getfix(bx,by));
...@@ -1390,6 +1375,208 @@ class NLE_squ8_CA extends NLE_squ4_CA { ...@@ -1390,6 +1375,208 @@ class NLE_squ8_CA extends NLE_squ4_CA {
//!println("Test: nn:",snn,"nl:",snl,"ll:",sll,"|",c0[0],c0[1],"|",c1[0],c1[1],"|",c2[0],c2[1],"|",c3[0],c3[1],"|",c4[0],c4[1],"|",c5[0],c5[1]); //!println("Test: nn:",snn,"nl:",snl,"ll:",sll,"|",c0[0],c0[1],"|",c1[0],c1[1],"|",c2[0],c2[1],"|",c3[0],c3[1],"|",c4[0],c4[1],"|",c5[0],c5[1]);
return count; return count;
} }
int find_groups(boolean fgn) {
//println("NLE_squ8_CA::find_groups(",fgn,")");
for (int ix=0;ix<nx;ix++)
for (int iy=0;iy<ny;iy++)
g[ix][iy] = 0;
for (int i=0;i<gs.length;i++) gs[i] = 0;
int k = 1;
for (int ix=0;ix<nx-1;ix++)
for (int iy=0;iy<ny-1;iy++) {
int state = get(ix,iy);
if ((fgn && isN(state)) || (!fgn && isL(state))) {
XY n1 = new XY(ix-1,iy-1); dirs.fix(n1,nx,ny);
XY n2 = new XY(ix ,iy-1); dirs.fix(n2,nx,ny);
XY n4 = new XY(ix-1,iy ); dirs.fix(n4,nx,ny);
XY n6 = new XY(ix-1,iy+1); dirs.fix(n6,nx,ny);
int label = k;
int sum = 1;
int lbl1 = g[n1.x][n1.y];
int lbl2 = g[n2.x][n2.y];
int lbl4 = g[n4.x][n4.y];
int lbl6 = g[n6.x][n6.y];
if (lbl1 != 0) { int s = gs[lbl1]; while (s<0) { lbl1 = -s; s = gs[lbl1]; } sum += s; label = min(label,lbl1); }
if (lbl2 != 0) { int s = gs[lbl2]; while (s<0) { lbl2 = -s; s = gs[lbl2]; } if (lbl2 != lbl1) sum += s; label = min(label,lbl2); }
if (lbl4 != 0) { int s = gs[lbl4]; while (s<0) { lbl4 = -s; s = gs[lbl4]; } if (lbl4 != lbl1 && lbl4 != lbl2) sum += s; label = min(label,lbl4); }
if (lbl6 != 0) { int s = gs[lbl6]; while (s<0) { lbl6 = -s; s = gs[lbl6]; } if (lbl6 != lbl1 && lbl6 != lbl2 && lbl6 != lbl4) sum += s; label = min(label,lbl6); }
int dk = 1;
g[ix][iy] = label;
if (lbl1 != 0) { gs[lbl1] = -label; dk = 0; }
if (lbl2 != 0) { gs[lbl2] = -label; dk = 0; }
if (lbl4 != 0) { gs[lbl4] = -label; dk = 0; }
if (lbl6 != 0) { gs[lbl6] = -label; dk = 0; }
gs[label] = sum;
k += dk;
}
}
{ int ix = nx-1;
for (int iy=0;iy<ny-1;iy++) {
int state = get(ix,iy);
if ((fgn && isN(state)) || (!fgn && isL(state))) {
XY n1 = new XY(ix-1,iy-1); dirs.fix(n1,nx,ny);
XY n2 = new XY(ix ,iy-1); dirs.fix(n2,nx,ny);
XY n3 = new XY(ix+1,iy-1); dirs.fix(n3,nx,ny);
XY n4 = new XY(ix-1,iy ); dirs.fix(n4,nx,ny);
XY n5 = new XY(ix+1,iy ); dirs.fix(n5,nx,ny);
XY n6 = new XY(ix-1,iy+1); dirs.fix(n6,nx,ny);
XY n8 = new XY(ix+1,iy+1); dirs.fix(n8,nx,ny);
int label = k;
int sum = 1;
int lbl1 = g[n1.x][n1.y];
int lbl2 = g[n2.x][n2.y];
int lbl3 = g[n3.x][n3.y];
int lbl4 = g[n4.x][n4.y];
int lbl5 = g[n5.x][n5.y];
int lbl6 = g[n6.x][n6.y];
int lbl8 = g[n8.x][n8.y];
if (lbl1 != 0) { int s = gs[lbl1]; while (s<0) { lbl1 = -s; s = gs[lbl1]; } sum += s; label = min(label,lbl1); }
if (lbl2 != 0) { int s = gs[lbl2]; while (s<0) { lbl2 = -s; s = gs[lbl2]; } if (lbl2 != lbl1) sum += s; label = min(label,lbl2); }
if (lbl3 != 0) { int s = gs[lbl3]; while (s<0) { lbl3 = -s; s = gs[lbl3]; } if (lbl3 != lbl1 && lbl3 != lbl2) sum += s; label = min(label,lbl3); }
if (lbl4 != 0) { int s = gs[lbl4]; while (s<0) { lbl4 = -s; s = gs[lbl4]; } if (lbl4 != lbl1 && lbl4 != lbl2 && lbl4 != lbl3) sum += s; label = min(label,lbl4); }
if (lbl5 != 0) { int s = gs[lbl5]; while (s<0) { lbl5 = -s; s = gs[lbl5]; } if (lbl5 != lbl1 && lbl5 != lbl2 && lbl5 != lbl3 && lbl5 != lbl4) sum += s; label = min(label,lbl5); }
if (lbl6 != 0) { int s = gs[lbl6]; while (s<0) { lbl6 = -s; s = gs[lbl6]; } if (lbl6 != lbl1 && lbl6 != lbl2 && lbl6 != lbl3 && lbl6 != lbl4 && lbl6 != lbl5) sum += s; label = min(label,lbl6); }
if (lbl8 != 0) { int s = gs[lbl8]; while (s<0) { lbl8 = -s; s = gs[lbl8]; } if (lbl8 != lbl1 && lbl8 != lbl2 && lbl8 != lbl3 && lbl8 != lbl4 && lbl8 != lbl5 && lbl8 != lbl6) sum += s; label = min(label,lbl8); }
int dk = 1;
g[ix][iy] = label;
if (lbl1 != 0) { gs[lbl1] = -label; dk = 0; }
if (lbl2 != 0) { gs[lbl2] = -label; dk = 0; }
if (lbl3 != 0) { gs[lbl3] = -label; dk = 0; }
if (lbl4 != 0) { gs[lbl4] = -label; dk = 0; }
if (lbl5 != 0) { gs[lbl5] = -label; dk = 0; }
if (lbl6 != 0) { gs[lbl6] = -label; dk = 0; }
if (lbl8 != 0) { gs[lbl8] = -label; dk = 0; }
gs[label] = sum;
k += dk;
}
}
}
{ int iy = ny-1;
for (int ix=0;ix<nx-1;ix++) {
int state = get(ix,iy);
if ((fgn && isN(state)) || (!fgn && isL(state))) {
XY n1 = new XY(ix-1,iy-1); dirs.fix(n1,nx,ny);
XY n2 = new XY(ix ,iy-1); dirs.fix(n2,nx,ny);
XY n3 = new XY(ix+1,iy-1); dirs.fix(n3,nx,ny);
XY n4 = new XY(ix-1,iy ); dirs.fix(n4,nx,ny);
XY n6 = new XY(ix-1,iy+1); dirs.fix(n6,nx,ny);
XY n7 = new XY(ix ,iy+1); dirs.fix(n7,nx,ny);
XY n8 = new XY(ix+1,iy+1); dirs.fix(n8,nx,ny);
int label = k;
int sum = 1;
int lbl1 = g[n1.x][n1.y];
int lbl2 = g[n2.x][n2.y];
int lbl3 = g[n3.x][n3.y];
int lbl4 = g[n4.x][n4.y];
int lbl6 = g[n6.x][n6.y];
int lbl7 = g[n7.x][n7.y];
int lbl8 = g[n8.x][n8.y];
if (lbl1 != 0) { int s = gs[lbl1]; while (s<0) { lbl1 = -s; s = gs[lbl1]; } sum += s; label = min(label,lbl1); }
if (lbl2 != 0) { int s = gs[lbl2]; while (s<0) { lbl2 = -s; s = gs[lbl2]; } if (lbl2 != lbl1) sum += s; label = min(label,lbl2); }
if (lbl3 != 0) { int s = gs[lbl3]; while (s<0) { lbl3 = -s; s = gs[lbl3]; } if (lbl3 != lbl1 && lbl3 != lbl2) sum += s; label = min(label,lbl3); }
if (lbl4 != 0) { int s = gs[lbl4]; while (s<0) { lbl4 = -s; s = gs[lbl4]; } if (lbl4 != lbl1 && lbl4 != lbl2 && lbl4 != lbl3) sum += s; label = min(label,lbl4); }
if (lbl6 != 0) { int s = gs[lbl6]; while (s<0) { lbl6 = -s; s = gs[lbl6]; } if (lbl6 != lbl1 && lbl6 != lbl2 && lbl6 != lbl3 && lbl6 != lbl4) sum += s; label = min(label,lbl6); }
if (lbl7 != 0) { int s = gs[lbl7]; while (s<0) { lbl7 = -s; s = gs[lbl7]; } if (lbl7 != lbl1 && lbl7 != lbl2 && lbl7 != lbl3 && lbl7 != lbl4 && lbl7 != lbl6) sum += s; label = min(label,lbl7); }
if (lbl8 != 0) { int s = gs[lbl8]; while (s<0) { lbl8 = -s; s = gs[lbl8]; } if (lbl8 != lbl1 && lbl8 != lbl2 && lbl8 != lbl3 && lbl8 != lbl4 && lbl8 != lbl6 && lbl8 != lbl7) sum += s; label = min(label,lbl8); }
int dk = 1;
g[ix][iy] = label;
if (lbl1 != 0) { gs[lbl1] = -label; dk = 0; }
if (lbl2 != 0) { gs[lbl2] = -label; dk = 0; }
if (lbl3 != 0) { gs[lbl3] = -label; dk = 0; }
if (lbl4 != 0) { gs[lbl4] = -label; dk = 0; }
if (lbl6 != 0) { gs[lbl6] = -label; dk = 0; }
if (lbl7 != 0) { gs[lbl7] = -label; dk = 0; }
if (lbl8 != 0) { gs[lbl8] = -label; dk = 0; }
gs[label] = sum;
k += dk;
}
}
}
{ int ix = nx-1;
int iy = ny-1;
int state = get(ix,iy);
if ((fgn && isN(state)) || (!fgn && isL(state))) {
XY n1 = new XY(ix-1,iy-1); dirs.fix(n1,nx,ny);
XY n2 = new XY(ix ,iy-1); dirs.fix(n2,nx,ny);
XY n3 = new XY(ix+1,iy-1); dirs.fix(n3,nx,ny);
XY n4 = new XY(ix-1,iy ); dirs.fix(n4,nx,ny);
XY n5 = new XY(ix+1,iy ); dirs.fix(n5,nx,ny);
XY n6 = new XY(ix-1,iy+1); dirs.fix(n6,nx,ny);
XY n7 = new XY(ix ,iy+1); dirs.fix(n7,nx,ny);
XY n8 = new XY(ix+1,iy+1); dirs.fix(n8,nx,ny);
int label = k;
int sum = 1;
int lbl1 = g[n1.x][n1.y];
int lbl2 = g[n2.x][n2.y];
int lbl3 = g[n3.x][n3.y];
int lbl4 = g[n4.x][n4.y];
int lbl5 = g[n5.x][n5.y];
int lbl6 = g[n6.x][n6.y];
int lbl7 = g[n7.x][n7.y];
int lbl8 = g[n8.x][n8.y];
if (lbl1 != 0) { int s = gs[lbl1]; while (s<0) { lbl1 = -s; s = gs[lbl1]; } sum += s; label = min(label,lbl1); }
if (lbl2 != 0) { int s = gs[lbl2]; while (s<0) { lbl2 = -s; s = gs[lbl2]; } if (lbl2 != lbl1) sum += s; label = min(label,lbl2); }
if (lbl3 != 0) { int s = gs[lbl3]; while (s<0) { lbl3 = -s; s = gs[lbl3]; } if (lbl3 != lbl1 && lbl3 != lbl2) sum += s; label = min(label,lbl3); }
if (lbl4 != 0) { int s = gs[lbl4]; while (s<0) { lbl4 = -s; s = gs[lbl4]; } if (lbl4 != lbl1 && lbl4 != lbl2 && lbl4 != lbl3) sum += s; label = min(label,lbl4); }
if (lbl5 != 0) { int s = gs[lbl5]; while (s<0) { lbl5 = -s; s = gs[lbl5]; } if (lbl5 != lbl1 && lbl5 != lbl2 && lbl5 != lbl3 && lbl5 != lbl4) sum += s; label = min(label,lbl5); }
if (lbl6 != 0) { int s = gs[lbl6]; while (s<0) { lbl6 = -s; s = gs[lbl6]; } if (lbl6 != lbl1 && lbl6 != lbl2 && lbl6 != lbl3 && lbl6 != lbl4 && lbl6 != lbl5) sum += s; label = min(label,lbl6); }
if (lbl7 != 0) { int s = gs[lbl7]; while (s<0) { lbl7 = -s; s = gs[lbl7]; } if (lbl7 != lbl1 && lbl7 != lbl2 && lbl7 != lbl3 && lbl7 != lbl4 && lbl7 != lbl5 && lbl7 != lbl6) sum += s; label = min(label,lbl7); }
if (lbl8 != 0) { int s = gs[lbl8]; while (s<0) { lbl8 = -s; s = gs[lbl8]; } if (lbl8 != lbl1 && lbl8 != lbl2 && lbl8 != lbl3 && lbl8 != lbl4 && lbl8 != lbl5 && lbl8 != lbl6 && lbl8 != lbl7) sum += s; label = min(label,lbl8); }
int dk = 1;
g[ix][iy] = label;
if (lbl1 != 0) { gs[lbl1] = -label; dk = 0; }
if (lbl2 != 0) { gs[lbl2] = -label; dk = 0; }
if (lbl3 != 0) { gs[lbl3] = -label; dk = 0; }
if (lbl4 != 0) { gs[lbl4] = -label; dk = 0; }
if (lbl5 != 0) { gs[lbl5] = -label; dk = 0; }
if (lbl6 != 0) { gs[lbl6] = -label; dk = 0; }
if (lbl7 != 0) { gs[lbl7] = -label; dk = 0; }
if (lbl8 != 0) { gs[lbl8] = -label; dk = 0; }
gs[label] = sum;
k += dk;
}
}
//print("GS:");
//for (int i=0;i<50;i++) print(" ",gs[i]);
//println();
//for (int i=0;i<20;i++) {
// for (int j=0;j<20;j++) print(" ",g[10+i][10+j]);
// println();
//}
return k;
}
void fill_debug() {
fill(L);
//for (int i=0;i<10;i++) cell[i][0] = E;
//for (int i=0;i<10;i++) cell[i][9] = E;
//for (int i=0;i<10;i++) cell[0][i] = E;
//for (int i=0;i<10;i++) cell[9][i] = E;
int bx = -10, by = -10;
//put_new_N(bx+nsize,by);
//put_new_N(bx,by+nsize);
// chess box
int n = 5;
for (int i=0;i<n;i++) {
put_new_N(bx+i*nsize*2,by);
put_new_N(bx+i*nsize*2+nsize,by+nsize);
put_new_N(bx,by+i*nsize*2);
put_new_N(bx+nsize,by+i*nsize*2+nsize);
put_new_N(bx+i*nsize*2,by+2*(n-1)*nsize);
put_new_N(bx+i*nsize*2+nsize,by+2*(n-1)*nsize+nsize);
put_new_N(bx+2*(n-1)*nsize,by+i*nsize*2);
put_new_N(bx+2*(n-1)*nsize+nsize,by+i*nsize*2+nsize);
}
find_groupsN();
}
} }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
...@@ -1696,7 +1883,6 @@ class NLE_hex_CA extends NLE_CA { ...@@ -1696,7 +1883,6 @@ class NLE_hex_CA extends NLE_CA {
g[ix][iy] = 0; g[ix][iy] = 0;
for (int i=0;i<gs.length;i++) gs[i] = 0; for (int i=0;i<gs.length;i++) gs[i] = 0;
int k = 1; int k = 1;
for (int iy=0;iy<ny-1;iy++) for (int iy=0;iy<ny-1;iy++)
for (int ix=0;ix<nx-1;ix++) { for (int ix=0;ix<nx-1;ix++) {
int state = get(ix,iy); int state = get(ix,iy);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment