1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-12-24 17:10:36 +00:00

struct fpattern exported

This commit is contained in:
Zeno Rogue 2019-09-05 09:56:49 +02:00
parent 9647cbd47e
commit fedb170b55

View File

@ -31,41 +31,45 @@ struct fgeomextra {
extern int subpathid;
extern int subpathorder;
#define MWDIM (prod ? 3 : WDIM+1)
bool isprime(int n) {
for(int k=2; k<n; k++) if(n%k == 0) return false;
return true;
}
#if HDR
#define MWDIM (prod ? 3 : WDIM+1)
struct matrix {
int a[MAXMDIM][MAXMDIM];
int* operator [] (int k) { return a[k]; }
const int* operator [] (int k) const { return a[k]; }
};
bool operator == (const matrix& A, const matrix& B) {
bool operator == (const matrix& B) const {
for(int i=0; i<MWDIM; i++) for(int j=0; j<MWDIM; j++)
if(A[i][j] != B[i][j]) return false;
if(self[i][j] != B[i][j]) return false;
return true;
}
bool operator != (const matrix& A, const matrix& B) {
bool operator != (const matrix& B) const {
for(int i=0; i<MWDIM; i++) for(int j=0; j<MWDIM; j++)
if(A[i][j] != B[i][j]) return true;
if(self[i][j] != B[i][j]) return true;
return false;
}
bool operator < (const matrix& A, const matrix& B) {
bool operator < (const matrix& B) const {
for(int i=0; i<MWDIM; i++) for(int j=0; j<MWDIM; j++)
if(A[i][j] != B[i][j]) return A[i][j] < B[i][j];
if(self[i][j] != B[i][j]) return self[i][j] < B[i][j];
return false;
}
int btspin(int id, int d) {
};
#endif
EX int btspin(int id, int d) {
return S7*(id/S7) + (id + d) % S7;
}
#if HDR
struct fpattern {
int Prime, wsquare, Field;
@ -217,12 +221,7 @@ struct fpattern {
return make_pair(gmul(a.first,b), a.second);
}
int order(const matrix& M) {
int cnt = 1;
matrix Po = M;
while(Po != Id) Po = mmul(Po, M), cnt++;
return cnt;
}
int order(const matrix& M);
string decodepath(int i) {
string s;
@ -237,7 +236,54 @@ struct fpattern {
int cs, sn, ch, sh;
int solve() {
int solve();
void build();
static const int MAXDIST = 120;
vector<char> disthep;
vector<char> disthex;
vector<char> distwall, distriver, distwall2, distriverleft, distriverright, distflower;
int distflower0;
vector<eItem> markers;
int getdist(pair<int,bool> a, vector<char>& dists);
int getdist(pair<int,bool> a, pair<int,bool> b);
int dijkstra(vector<char>& dists, vector<int> indist[MAXDIST]);
void analyze();
int maxdist, otherpole, circrad, wallid, wallorder, riverid;
bool easy(int i) {
return i < Prime || !(i % Prime);
}
// 11 * 25
// (1+z+z^3) * (1+z^3+z^4) ==
// 1+z+z^7 == 1+z+z^2(z^5) == 1+z+z^2(1+z^2) = 1+z+z^2+z^4
void init(int p) {
Prime = p;
if(solve()) {
printf("error: could not solve the fieldpattern\n");
exit(1);
}
build();
}
fpattern(int p) {
if(!p) return;
init(p);
}
void findsubpath();
};
#endif
int fpattern::solve() {
for(int a=0; a<MWDIM; a++) for(int b=0; b<MWDIM; b++) Id[a][b] = a==b?1:0;
@ -260,15 +306,15 @@ struct fpattern {
}
} else wsquare = 0;
#ifdef EASY
#ifdef EASY
std::vector<int> sqrts(Prime, 0);
for(int k=1-Prime; k<Prime; k++) sqrts[sqr(k)] = k;
int fmax = Prime;
#else
#else
std::vector<int> sqrts(Field);
for(int k=0; k<Field; k++) sqrts[sqr(k)] = k;
int fmax = Field;
#endif
#endif
if(Prime == 13 && wsquare && false) {
for(int i=0; i<Prime; i++) printf("%3d", sqrts[i]);
@ -322,7 +368,14 @@ struct fpattern {
return 2;
}
void build() {
int fpattern::order(const matrix& M) {
int cnt = 1;
matrix Po = M;
while(Po != Id) Po = mmul(Po, M), cnt++;
return cnt;
}
void fpattern::build() {
for(int i=0; i<isize(qpaths); i++) {
matrix M = strtomatrix(qpaths[i]);
@ -386,17 +439,7 @@ struct fpattern {
DEBB(DF_FIELD, ("Built.\n"));
}
static const int MAXDIST = 120;
vector<char> disthep;
vector<char> disthex;
vector<char> distwall, distriver, distwall2, distriverleft, distriverright, distflower;
int distflower0;
vector<eItem> markers;
int getdist(pair<int,bool> a, vector<char>& dists) {
int fpattern::getdist(pair<int,bool> a, vector<char>& dists) {
if(!a.second) return dists[a.first];
int m = MAXDIST;
int ma = dists[a.first];
@ -412,15 +455,13 @@ struct fpattern {
return m;
}
int getdist(pair<int,bool> a, pair<int,bool> b) {
int fpattern::getdist(pair<int,bool> a, pair<int,bool> b) {
if(a.first == b.first) return a.second == b.second ? 0 : 1;
if(b.first) a.first = gmul(a.first, inverses[b.first]), b.first = 0;
return getdist(a, b.second ? disthex : disthep);
}
int maxdist, otherpole, circrad, wallid, wallorder, riverid;
int dijkstra(vector<char>& dists, vector<int> indist[MAXDIST]) {
int fpattern::dijkstra(vector<char>& dists, vector<int> indist[MAXDIST]) {
int N = connections.size();
dists.resize(N);
for(int i=0; i<N; i++) dists[i] = MAXDIST-1;
@ -445,7 +486,7 @@ struct fpattern {
return maxd;
}
void analyze() {
void fpattern::analyze() {
if(WDIM == 3) return;
@ -654,40 +695,6 @@ struct fpattern {
DEBB(DF_FIELD, ("river-wall distance = %d\n", distriver[0]));
}
bool easy(int i) {
return i < Prime || !(i % Prime);
}
// 11 * 25
// (1+z+z^3) * (1+z^3+z^4) ==
// 1+z+z^7 == 1+z+z^2(z^5) == 1+z+z^2(1+z^2) = 1+z+z^2+z^4
void init(int p) {
Prime = p;
if(solve()) {
printf("error: could not solve the fieldpattern\n");
exit(1);
}
build();
}
fpattern(int p) {
if(!p) return;
init(p);
}
void findsubpath() {
int N = isize(matrices);
for(int i=1; i<N; i++)
if(gpow(i, Prime) == 0) {
subpathid = i;
subpathorder = Prime;
DEBB(DF_FIELD, ("Subpath found: %s\n", decodepath(i).c_str()));
return;
}
}
};
int fpattern::orderstats() {
int N = isize(matrices);
@ -713,6 +720,16 @@ int fpattern::orderstats() {
return ordsample[Prime];
}
void fpattern::findsubpath() {
int N = isize(matrices);
for(int i=1; i<N; i++)
if(gpow(i, Prime) == 0) {
subpathid = i;
subpathorder = Prime;
DEBB(DF_FIELD, ("Subpath found: %s\n", decodepath(i).c_str()));
return;
}
}
fpattern fp43(43);
@ -747,7 +764,8 @@ void info() {
printf("cases found = %d (%d hard)\n", cases, hard);
}
fpattern current_quotient_field(0), fp_invalid(0);
EX fpattern current_quotient_field = fpattern(0);
EX fpattern fp_invalid = fpattern(0);
bool quotient_field_changed;
EX struct fpattern& getcurrfp() {