mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-07-05 03:02:49 +00:00
struct fpattern exported
This commit is contained in:
parent
9647cbd47e
commit
fedb170b55
162
fieldpattern.cpp
162
fieldpattern.cpp
@ -31,41 +31,45 @@ struct fgeomextra {
|
|||||||
extern int subpathid;
|
extern int subpathid;
|
||||||
extern int subpathorder;
|
extern int subpathorder;
|
||||||
|
|
||||||
#define MWDIM (prod ? 3 : WDIM+1)
|
|
||||||
|
|
||||||
bool isprime(int n) {
|
bool isprime(int n) {
|
||||||
for(int k=2; k<n; k++) if(n%k == 0) return false;
|
for(int k=2; k<n; k++) if(n%k == 0) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if HDR
|
||||||
|
#define MWDIM (prod ? 3 : WDIM+1)
|
||||||
|
|
||||||
struct matrix {
|
struct matrix {
|
||||||
int a[MAXMDIM][MAXMDIM];
|
int a[MAXMDIM][MAXMDIM];
|
||||||
int* operator [] (int k) { return a[k]; }
|
int* operator [] (int k) { return a[k]; }
|
||||||
const int* operator [] (int k) const { 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++)
|
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;
|
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++)
|
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;
|
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++)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int btspin(int id, int d) {
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
EX int btspin(int id, int d) {
|
||||||
return S7*(id/S7) + (id + d) % S7;
|
return S7*(id/S7) + (id + d) % S7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if HDR
|
||||||
struct fpattern {
|
struct fpattern {
|
||||||
|
|
||||||
int Prime, wsquare, Field;
|
int Prime, wsquare, Field;
|
||||||
@ -217,12 +221,7 @@ struct fpattern {
|
|||||||
return make_pair(gmul(a.first,b), a.second);
|
return make_pair(gmul(a.first,b), a.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
int order(const matrix& M) {
|
int order(const matrix& M);
|
||||||
int cnt = 1;
|
|
||||||
matrix Po = M;
|
|
||||||
while(Po != Id) Po = mmul(Po, M), cnt++;
|
|
||||||
return cnt;
|
|
||||||
}
|
|
||||||
|
|
||||||
string decodepath(int i) {
|
string decodepath(int i) {
|
||||||
string s;
|
string s;
|
||||||
@ -237,7 +236,54 @@ struct fpattern {
|
|||||||
|
|
||||||
int cs, sn, ch, sh;
|
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;
|
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;
|
} else wsquare = 0;
|
||||||
|
|
||||||
#ifdef EASY
|
#ifdef EASY
|
||||||
std::vector<int> sqrts(Prime, 0);
|
std::vector<int> sqrts(Prime, 0);
|
||||||
for(int k=1-Prime; k<Prime; k++) sqrts[sqr(k)] = k;
|
for(int k=1-Prime; k<Prime; k++) sqrts[sqr(k)] = k;
|
||||||
int fmax = Prime;
|
int fmax = Prime;
|
||||||
#else
|
#else
|
||||||
std::vector<int> sqrts(Field);
|
std::vector<int> sqrts(Field);
|
||||||
for(int k=0; k<Field; k++) sqrts[sqr(k)] = k;
|
for(int k=0; k<Field; k++) sqrts[sqr(k)] = k;
|
||||||
int fmax = Field;
|
int fmax = Field;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(Prime == 13 && wsquare && false) {
|
if(Prime == 13 && wsquare && false) {
|
||||||
for(int i=0; i<Prime; i++) printf("%3d", sqrts[i]);
|
for(int i=0; i<Prime; i++) printf("%3d", sqrts[i]);
|
||||||
@ -322,7 +368,14 @@ struct fpattern {
|
|||||||
return 2;
|
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++) {
|
for(int i=0; i<isize(qpaths); i++) {
|
||||||
matrix M = strtomatrix(qpaths[i]);
|
matrix M = strtomatrix(qpaths[i]);
|
||||||
@ -386,17 +439,7 @@ struct fpattern {
|
|||||||
DEBB(DF_FIELD, ("Built.\n"));
|
DEBB(DF_FIELD, ("Built.\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
static const int MAXDIST = 120;
|
int fpattern::getdist(pair<int,bool> a, vector<char>& dists) {
|
||||||
|
|
||||||
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) {
|
|
||||||
if(!a.second) return dists[a.first];
|
if(!a.second) return dists[a.first];
|
||||||
int m = MAXDIST;
|
int m = MAXDIST;
|
||||||
int ma = dists[a.first];
|
int ma = dists[a.first];
|
||||||
@ -412,15 +455,13 @@ struct fpattern {
|
|||||||
return m;
|
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(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;
|
if(b.first) a.first = gmul(a.first, inverses[b.first]), b.first = 0;
|
||||||
return getdist(a, b.second ? disthex : disthep);
|
return getdist(a, b.second ? disthex : disthep);
|
||||||
}
|
}
|
||||||
|
|
||||||
int maxdist, otherpole, circrad, wallid, wallorder, riverid;
|
int fpattern::dijkstra(vector<char>& dists, vector<int> indist[MAXDIST]) {
|
||||||
|
|
||||||
int dijkstra(vector<char>& dists, vector<int> indist[MAXDIST]) {
|
|
||||||
int N = connections.size();
|
int N = connections.size();
|
||||||
dists.resize(N);
|
dists.resize(N);
|
||||||
for(int i=0; i<N; i++) dists[i] = MAXDIST-1;
|
for(int i=0; i<N; i++) dists[i] = MAXDIST-1;
|
||||||
@ -445,7 +486,7 @@ struct fpattern {
|
|||||||
return maxd;
|
return maxd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void analyze() {
|
void fpattern::analyze() {
|
||||||
|
|
||||||
if(WDIM == 3) return;
|
if(WDIM == 3) return;
|
||||||
|
|
||||||
@ -654,40 +695,6 @@ struct fpattern {
|
|||||||
DEBB(DF_FIELD, ("river-wall distance = %d\n", distriver[0]));
|
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 fpattern::orderstats() {
|
||||||
int N = isize(matrices);
|
int N = isize(matrices);
|
||||||
|
|
||||||
@ -713,6 +720,16 @@ int fpattern::orderstats() {
|
|||||||
return ordsample[Prime];
|
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);
|
fpattern fp43(43);
|
||||||
|
|
||||||
@ -747,7 +764,8 @@ void info() {
|
|||||||
printf("cases found = %d (%d hard)\n", cases, hard);
|
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;
|
bool quotient_field_changed;
|
||||||
|
|
||||||
EX struct fpattern& getcurrfp() {
|
EX struct fpattern& getcurrfp() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user