1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-27 22:39:53 +00:00

magmahep: generalized to not only heptagons, debug disable

This commit is contained in:
Zeno Rogue 2020-06-08 12:25:27 +02:00
parent 295bda1438
commit bcdd404e42

View File

@ -5,8 +5,12 @@
namespace hr {
int magmav = 7;
/* vertices of the Magma's heptagon */
array<hyperpoint, 8> vertices;
vector<hyperpoint> vertices;
hyperpoint hcenter;
/* how are all Magma's heptagons transformed and colored */
vector<pair<transmatrix, color_t>> heps;
@ -17,6 +21,8 @@ int magmacount = 1000;
int magmalong = 10;
bool magmadebug = false;
/* transformation from the original to the next heptagon;
edge a of the original heptagon matches edge b of the next heptagon */
@ -43,12 +49,22 @@ EX transmatrix get_adj(int a, int b) {
void make() {
int& v = magmav;
/* compute the vertices */
for(int i=0; i<=7; i++)
vertices[i] = spin(2*M_PI*i/7) * xpush0(1);
vertices.resize(magmav+1);
for(int i=0; i<=magmav; i++)
vertices[i] = spin(2*M_PI*(i+(v-7)/4.)/v) * xpush0(1);
ld xx = vertices[2][0];
vertices[3][0] = 2 * xx - vertices[3][0];
vertices[4][0] = 2 * xx - vertices[4][0];
int down = v/2 + 2;
for(int k=3; k<down; k++)
vertices[k][0] = 2 * xx - vertices[k][0];
hcenter = Hypc;
for(int i=0; i<magmav; i++) hcenter += vertices[i];
hcenter = normalize(hcenter);
heps.emplace_back(Id, 0xFFFFFFFF);
@ -60,51 +76,56 @@ void make() {
/* create the core */
int last = v-1;
int t = 3;
switch(magmashape) {
case 1:
for(int i=0; i<13; i++)
advance(0, 3);
for(int i=1; i<2*v; i++)
advance(0, t);
break;
case 2:
for(int i=0; i<8; i++)
advance(3, 0);
advance(3, 6);
for(int i=0; i<t+1; i++)
advance(t, 0);
advance(t, last);
break;
case 3:
for(int a=0; a<2; a++) {
advance(2, 0);
for(int i=a; i<8; i++)
advance(3, 0);
advance(t-1, 0);
for(int i=a; i<v+1; i++)
advance(t, 0);
}
break;
case 4:
for(int a=0; a<4; a++)
advance(3, 0);
advance(3, 1);
for(int a=0; a<4; a++)
advance(3, 0);
case 4: {
advance(t, 1);
for(int a=0; a<v-3; a++)
advance(t, 0);
advance(t, 1);
for(int a=0; a<v-4; a++)
advance(t, 0);
break;
}
case 5:
for(int a=0; a<6; a++) {
advance(3, 0);
for(int a=0; a<v-1; a++) {
advance(t, 0);
}
for(int b=0; b<magmalong; b++) {
advance(3, 6);
advance(3, 0);
advance(t, last);
advance(t, 0);
}
for(int a=0; a<7; a++) {
advance(3, 0);
for(int a=0; a<v; a++) {
advance(t, 0);
}
for(int b=0; b<magmalong; b++) {
advance(3, 6);
advance(3, 0);
advance(t, last);
advance(t, 0);
}
break;
}
@ -112,7 +133,7 @@ void make() {
/* center the core */
hyperpoint center = Hypc;
for(auto& h: heps) for(int i=0; i<7; i++)
for(auto& h: heps) for(int i=0; i<v; i++)
center += h.first * vertices[i];
center = normalize(center);
@ -123,63 +144,57 @@ void make() {
for(int a=0; a<magmacount; a++) {
hyperpoint p = heps.back().first * vertices[2];
int small = 0;
int big = 0;
int inner = 0;
for(auto h: heps)
for(int a=0; a<7; a++)
int total = 0;
int big = v - 2;
for(auto& h: heps)
for(int a=0; a<v; a++)
if(hdist(h.first * vertices[a], p) < .001) {
if(a == 2 || a == 5)
small ++;
else if(a == 3 || a == 4)
inner ++;
if(a == 2 || a == down)
total ++;
else if(a > 2 && a < down)
total += 2*v - big;
else
big++;
total += big;
}
if(small == 14 && inner == 0 && big == 0)
advance(5, 5, true);
println(hlog, "total ", total);
if(total == 2*v)
advance(down, down, true);
else if(small == 4 && big == 2 && inner == 0)
advance(5, 5, true);
else if(small == 9 && big == 1 && inner == 0)
advance(5, 5, true);
else if(inner == 1 && small == 5 && big == 0)
advance(5, 5, true);
else if(small == 4 && big == 1 && inner == 0)
advance(3, 6);
else if(big == 1 && small < 4 && inner == 0)
advance(3, 0);
else if(big == 2 && small < 4 && inner == 0)
advance(3, 0);
else {
println(hlog, "big = ", big, "small = ", small);
}
else if(total == 2 * v - big)
advance(t, last);
else if(total < 2 * v)
advance(t, 0);
else
break;
}
}
void draw_at(transmatrix T, color_t col) {
for(int i=0; i<=7; i++)
void draw_at(transmatrix T, color_t col, int id) {
for(int i=0; i<=magmav; i++)
curvepoint(T * vertices[i]);
queuecurve(0xFF, col, PPR::LINE);
for(int i=0; i<7; i++) {
if(magmadebug) {
for(int i=0; i<magmav; i++) {
hyperpoint h = mid(vertices[i], vertices[i+1]);
h += spin(M_PI/2) * (vertices[i+1] - vertices[i]) * (among(i, 2, 3, 4) ? 1 : 1) * .05;
h += spin(M_PI/2) * (vertices[i+1] - vertices[i]) * .05;
queuestr(T * rgpushxto0(h), 0.4, its(i), 0x80);
}
queuestr(T * rgpushxto0(hcenter), 0.4, "#"+its(id), 0x80);
}
}
void draw_magma() {
if(heps.empty()) make();
transmatrix V = ggmatrix(currentmap->gamestart());
int id = 0;
for(auto h: heps)
draw_at(V * h.first, h.second);
draw_at(V * h.first, h.second, id++);
}
int readArgs() {
@ -190,6 +205,10 @@ int readArgs() {
shift(); magmashape = argi();
}
else if(argis("-magmav")) {
shift(); magmav = argi();
}
else if(argis("-magmacount")) {
shift(); magmacount = argi();
}
@ -198,6 +217,10 @@ int readArgs() {
shift(); magmalong = argi();
}
else if(argis("-magmadebug")) {
shift(); magmadebug = argi();
}
else return 1;
return 0;
}