Euclidean square grid

This commit is contained in:
Zeno Rogue 2017-12-18 13:00:36 +01:00
parent 3e0f751a2c
commit 836ed087df
7 changed files with 105 additions and 32 deletions

View File

@ -606,15 +606,34 @@ cell*& euclideanAt(eucoord x, eucoord y) {
cell*& euclideanAtCreate(eucoord x, eucoord y) { cell*& euclideanAtCreate(eucoord x, eucoord y) {
cell*& c = euclideanAt(x,y); cell*& c = euclideanAt(x,y);
if(!c) { if(!c) {
c = newCell(6, NULL); c = newCell(a4 ? (nontruncated || ((x^y^1) & 1) ? 4 : 8) : 6, NULL);
c->master = encodeMaster(x,y); c->master = encodeMaster(x,y);
euclideanAt(x,y) = c; euclideanAt(x,y) = c;
eumerge(c, euclideanAt(x+1,y), 0, 3); if(c->type == 4) {
eumerge(c, euclideanAt(x,y+1), 1, 4); int m = nontruncated ? 1 : 2;
eumerge(c, euclideanAt(x-1,y+1), 2, 5); eumerge(c, euclideanAt(x+1,y), 0, 2 * m);
eumerge(c, euclideanAt(x-1,y), 3, 0); eumerge(c, euclideanAt(x,y+1), 1, 3 * m);
eumerge(c, euclideanAt(x,y-1), 4, 1); eumerge(c, euclideanAt(x-1,y), 2, 0 * m);
eumerge(c, euclideanAt(x+1,y-1), 5, 2); eumerge(c, euclideanAt(x,y-1), 3, 1 * m);
}
else if(c->type == 8) {
eumerge(c, euclideanAt(x+1,y), 0, 2);
eumerge(c, euclideanAt(x+1,y+1), 1, 5);
eumerge(c, euclideanAt(x,y+1), 2, 3);
eumerge(c, euclideanAt(x-1,y+1), 3, 7);
eumerge(c, euclideanAt(x-1,y), 4, 0);
eumerge(c, euclideanAt(x-1,y-1), 5, 1);
eumerge(c, euclideanAt(x,y-1), 6, 1);
eumerge(c, euclideanAt(x+1,y-1), 7, 3);
}
else /* 6 */ {
eumerge(c, euclideanAt(x+1,y), 0, 3);
eumerge(c, euclideanAt(x,y+1), 1, 4);
eumerge(c, euclideanAt(x-1,y+1), 2, 5);
eumerge(c, euclideanAt(x-1,y), 3, 0);
eumerge(c, euclideanAt(x,y-1), 4, 1);
eumerge(c, euclideanAt(x+1,y-1), 5, 2);
}
} }
return c; return c;
} }
@ -719,6 +738,7 @@ void verifycells(heptagon *at) {
int eudist(short sx, short sy) { int eudist(short sx, short sy) {
int z0 = abs(sx); int z0 = abs(sx);
int z1 = abs(sy); int z1 = abs(sy);
if(a4) return z0 + z1;
int z2 = abs(sx+sy); int z2 = abs(sx+sy);
return max(max(z0,z1), z2); return max(max(z0,z1), z2);
} }

View File

@ -1620,5 +1620,6 @@ geometryinfo ginf[gGUARD] = {
{"four heptagons", "4x7", 7, 4, 0, 0, {{4, 3}}}, {"four heptagons", "4x7", 7, 4, 0, 0, {{4, 3}}},
{"cube", "3x4", 4, 3, 0, 2, {{SEE_ALL, SEE_ALL}}}, {"cube", "3x4", 4, 3, 0, 2, {{SEE_ALL, SEE_ALL}}},
{"tetrahedron (buggy)", "3x3", 3, 3, 0, 2, {{SEE_ALL, SEE_ALL}}}, {"tetrahedron (buggy)", "3x3", 3, 3, 0, 2, {{SEE_ALL, SEE_ALL}}},
{"square grid", "4x4", 4, 4, 0, 1, {{7, 7}}}
}; };

View File

@ -187,7 +187,7 @@ enum eLand { laNone, laBarrier, laCrossroads, laDesert, laIce, laCaves, laJungle
laDual, laSnakeNest laDual, laSnakeNest
}; };
enum eGeometry {gNormal, gEuclid, gSphere, gElliptic, gQuotient, gQuotient2, gTorus, gOctagon, g45, g46, g47, gSmallSphere, gTinySphere, gGUARD}; enum eGeometry {gNormal, gEuclid, gSphere, gElliptic, gQuotient, gQuotient2, gTorus, gOctagon, g45, g46, g47, gSmallSphere, gTinySphere, gEuclidSquare, gGUARD};
struct geometryinfo { struct geometryinfo {
const char* name; const char* name;

View File

@ -53,14 +53,37 @@ void precalc() {
// dynamicval<eGeometry> g(geometry, gNormal); // dynamicval<eGeometry> g(geometry, gNormal);
// precalc(); } // precalc(); }
// for(int i=0; i<S84; i++) spinmatrix[i] = spin(i * M_PI / S42); // for(int i=0; i<S84; i++) spinmatrix[i] = spin(i * M_PI / S42);
crossf = .5; if(a4 && nontruncated) {
tessf = crossf * sqrt(3); crossf = .5;
hexf = tessf/3; hexf = .5;
hcrossf = crossf; hcrossf = crossf * sqrt(2) / 2;
hexhexdist = crossf; hexhexdist = crossf;
hexvdist = hexf; hexvdist = hexf;
hepvdist = crossf; hepvdist = hexf;
rhexf = hexf; rhexf = crossf * sqrt(2) / 2;
}
else if(a4) {
ld s2 = sqrt(2);
ld xx = 1 - s2 / 2;
crossf = .5;
tessf = crossf * s2;
hexf = .5 * xx * s2;
hcrossf = crossf;
hexhexdist = crossf * s2;
hexvdist = crossf * hypot(1-xx, xx);
hepvdist = crossf;
rhexf = hexf;
}
else {
crossf = .5;
tessf = crossf * sqrt(3);
hexf = tessf/3;
hcrossf = crossf;
hexhexdist = crossf;
hexvdist = hexf;
hepvdist = crossf;
rhexf = hexf;
}
goto finish; goto finish;
} }

View File

@ -158,6 +158,7 @@ void drawSpeed(const transmatrix& V) {
int ctof(cell *c) { int ctof(cell *c) {
if(nontruncated) return 1; if(nontruncated) return 1;
if(euclid && a4) return !(eupattern(c) & 1);
// if(euclid) return 0; // if(euclid) return 0;
return ishept(c) ? 1 : 0; return ishept(c) ? 1 : 0;
// c->type == 6 ? 0 : 1; // c->type == 6 ? 0 : 1;

View File

@ -374,26 +374,47 @@ int mindx=-7, mindy=-7, maxdx=7, maxdy=7;
transmatrix eumove(ld x, ld y) { transmatrix eumove(ld x, ld y) {
transmatrix Mat = Id; transmatrix Mat = Id;
Mat[2][2] = 1; Mat[2][2] = 1;
Mat[0][2] += (x + y * .5) * eurad;
// Mat[2][0] += (x + y * .5) * eurad; if(a4) {
Mat[1][2] += y * q3 /2 * eurad; Mat[0][2] += x * eurad;
// Mat[2][1] += y * q3 /2 * eurad; Mat[1][2] += y * eurad;
}
else {
Mat[0][2] += (x + y * .5) * eurad;
// Mat[2][0] += (x + y * .5) * eurad;
Mat[1][2] += y * q3 /2 * eurad;
// Mat[2][1] += y * q3 /2 * eurad;
}
ld v = a4 ? 1 : q3;
while(Mat[0][2] <= -16384 * eurad) Mat[0][2] += 32768 * eurad; while(Mat[0][2] <= -16384 * eurad) Mat[0][2] += 32768 * eurad;
while(Mat[0][2] >= 16384 * eurad) Mat[0][2] -= 32768 * eurad; while(Mat[0][2] >= 16384 * eurad) Mat[0][2] -= 32768 * eurad;
while(Mat[1][2] <= -16384 * q3 * eurad) Mat[1][2] += 32768 * q3 * eurad; while(Mat[1][2] <= -16384 * v * eurad) Mat[1][2] += 32768 * v * eurad;
while(Mat[1][2] >= 16384 * q3 * eurad) Mat[1][2] -= 32768 * q3 * eurad; while(Mat[1][2] >= 16384 * v * eurad) Mat[1][2] -= 32768 * v * eurad;
return Mat; return Mat;
} }
transmatrix eumovedir(int d) { transmatrix eumovedir(int d) {
d = fix6(d); if(a4) {
switch(d) { d = d & 3;
case 0: return eumove(1,0); switch(d) {
case 1: return eumove(0,1); case 0: return eumove(1,0);
case 2: return eumove(-1,1); case 1: return eumove(0,1);
case 3: return eumove(-1,0); case 2: return eumove(-1,0);
case 4: return eumove(0,-1); case 3: return eumove(0,-1);
case 5: return eumove(1,-1); }
}
else {
d = fix6(d);
switch(d) {
case 0: return eumove(1,0);
case 1: return eumove(0,1);
case 2: return eumove(-1,1);
case 3: return eumove(-1,0);
case 4: return eumove(0,-1);
case 5: return eumove(1,-1);
}
} }
return eumove(0,0); return eumove(0,0);
} }
@ -404,6 +425,7 @@ ld matrixnorm(const transmatrix& Mat) {
void drawEuclidean() { void drawEuclidean() {
DEBB(DF_GRAPH, (debugfile,"drawEuclidean\n")); DEBB(DF_GRAPH, (debugfile,"drawEuclidean\n"));
sphereflip = Id;
eucoord px=0, py=0; eucoord px=0, py=0;
if(!centerover) centerover = cwt.c; if(!centerover) centerover = cwt.c;
// printf("centerover = %p player = %p [%d,%d]-[%d,%d]\n", lcenterover, cwt.c, // printf("centerover = %p player = %p [%d,%d]-[%d,%d]\n", lcenterover, cwt.c,

View File

@ -3,6 +3,12 @@
// Copyright (C) 2011-2017 Zeno Rogue, see 'hyper.cpp' for details // Copyright (C) 2011-2017 Zeno Rogue, see 'hyper.cpp' for details
int eupattern(cell *c) { int eupattern(cell *c) {
if(a4) {
if(torus) return (decodeId(c->master)*2) % 3;
eucoord x, y;
decodeMaster(c->master, x, y);
return (x&1) + (y&1);
}
if(torus) return (decodeId(c->master)*2) % 3; if(torus) return (decodeId(c->master)*2) % 3;
eucoord x, y; eucoord x, y;
decodeMaster(c->master, x, y); decodeMaster(c->master, x, y);
@ -844,7 +850,8 @@ int pattern_threecolor(cell *c) {
int i = si.id; int i = si.id;
return i >> 2; return i >> 2;
} }
if(S7 == 4) { if(euclid) return (eupattern(c)+1) % 3;
if(S7 == 4 && S3 == 3) {
int codesN[6] = {0,1,2,1,2,0}; int codesN[6] = {0,1,2,1,2,0};
if(nontruncated) if(nontruncated)
return codesN[c->master->fiftyval]; return codesN[c->master->fiftyval];
@ -872,7 +879,6 @@ int pattern_threecolor(cell *c) {
} }
if(S7 == 3 && nontruncated) if(S7 == 3 && nontruncated)
return c->master->fiftyval; return c->master->fiftyval;
if(euclid) return (eupattern(c)+1) % 3;
return !ishept(c); return !ishept(c);
} }