Commit 95b06ec5 authored by Adam P. Goucher's avatar Adam P. Goucher

Slight refactoring to make lifelib ready to support hexagonal rules

parent 98a137df
Pipeline #38619420 passed with stage
in 3 minutes and 13 seconds
......@@ -270,6 +270,67 @@ namespace apg {
return tldiag;
}
bool getdbox(int64_t *bbox) {
// These are set outside the admissible range:
int64_t tl = 20000000000000ll;
int64_t br = -20000000000000ll;
int64_t bl = 20000000000000ll;
int64_t tr = -20000000000000ll;
bool nonempty = false;
std::map<std::pair<int32_t, int32_t>, uint64_t>::iterator it;
for (it = world.begin(); it != world.end(); /* no increment */ ) {
uint64_t tile = it->second;
if (tile == 0) {
// Empty tile; erase:
world.erase(it++);
} else {
// Only determine bounding box if bbox is a valid pointer:
if (bbox != 0) {
int64_t abscissa = ((int64_t) it->first.first ) * 8;
int64_t ordinate = ((int64_t) it->first.second) * 8;
int64_t major = abscissa + ordinate;
int64_t minor = abscissa - ordinate;
if (major < tl) {
int64_t dx = uint64_tl(tile);
if (major + dx < tl) { tl = major + dx; }
}
if (major + 14 > br) {
int64_t dx = uint64_br(tile);
if (major + dx > br) { br = major + dx; }
}
if (minor < bl) {
int64_t dy = uint64_bl(tile);
if (minor + dy < bl) { bl = minor + dy; }
}
if (minor + 14 > tr) {
int64_t dy = uint64_tr(tile);
if (minor + dy > tr) { tr = minor + dy; }
}
}
// We've encountered a non-empty tile; proceed:
nonempty = true;
it++;
}
}
if (nonempty && (bbox != 0)) {
bbox[0] = tl;
bbox[1] = bl - 7;
bbox[2] = (1 + br - tl);
bbox[3] = (1 + tr - bl);
}
return nonempty;
}
bool getbbox(int64_t *bbox) {
// These are set outside the admissible range:
......@@ -329,6 +390,11 @@ namespace apg {
return nonempty;
}
bool getboct(int64_t *boct) {
getbbox(boct);
return getdbox(boct + 4);
}
bitworld& clean() {
std::map<std::pair<int32_t, int32_t>, uint64_t>::iterator it;
for (it = world.begin(); it != world.end(); /* no increment */ ) {
......@@ -631,6 +697,45 @@ namespace apg {
return s;
}
std::string wechslerhex(std::vector<bitworld> &bwv) {
std::string rep = "#";
int64_t rect[8] = {0ll};
bitworld bw = bwv[0];
for (uint64_t i = 1; i < bwv.size(); i++) { bw += bwv[i]; }
bw.getboct(rect);
int64_t rect4 = rect[0] + rect[2] - 1;
int64_t rect5 = rect[1] + rect[3] - 1;
int64_t rect9 = rect[5] + rect[7] - 1;
if ((rect[2] + 2) * (rect[3] + 2) > 5000) { return rep; }
if ((rect[2] + 2) * (rect[7] + 2) > 5000) { return rep; }
if ((rect[7] + 2) * (rect[3] + 2) > 5000) { return rep; }
rep = comprep(rep, canonise_orientation(bwv, rect[2], rect[3], rect[0], rect[1], 1, 0, 0, 1));
rep = comprep(rep, canonise_orientation(bwv, rect[3], rect[2], rect[0], rect[1], 0, 1, 1, 0));
rep = comprep(rep, canonise_orientation(bwv, rect[3], rect[7], rect9 + rect[1], rect[1], 1, -1, 1, 0));
rep = comprep(rep, canonise_orientation(bwv, rect[7], rect[3], rect9 + rect[1], rect[1], -1, 1, 0, 1));
rep = comprep(rep, canonise_orientation(bwv, rect[7], rect[2], rect4, rect4 - rect9, 0, -1, 1, -1));
rep = comprep(rep, canonise_orientation(bwv, rect[2], rect[7], rect4, rect4 - rect9, -1, 0, -1, 1));
rep = comprep(rep, canonise_orientation(bwv, rect[2], rect[3], rect4, rect5, -1, 0, 0, -1));
rep = comprep(rep, canonise_orientation(bwv, rect[3], rect[2], rect4, rect5, 0, -1, -1, 0));
rep = comprep(rep, canonise_orientation(bwv, rect[3], rect[7], rect[5] + rect5, rect5, -1, 1, -1, 0));
rep = comprep(rep, canonise_orientation(bwv, rect[7], rect[3], rect[5] + rect5, rect5, 1, -1, 0, -1));
rep = comprep(rep, canonise_orientation(bwv, rect[7], rect[2], rect[0], rect[0] - rect[5], 0, 1, -1, 1));
rep = comprep(rep, canonise_orientation(bwv, rect[2], rect[7], rect[0], rect[0] - rect[5], 1, 0, 1, -1));
return rep;
}
std::string wechslerise(std::vector<bitworld> &bwv, int64_t *rect) {
std::string rep = "#";
......
......@@ -523,6 +523,21 @@ namespace apg {
return dt;
}
bool isHexagonal() {
std::string rule = rulestring;
if (rule.length() == 0) { return false; }
// Remove history suffix:
if ((rule.length() >= 8) && (rule.substr(rule.length() - 6) == "istory")) {
rule = rule.substr(0, rule.length() - 7);
}
// Match uppercase 'H' and lowercase 'h':
return (((int) rule[rule.length() - 1]) & 31) == 8;
}
std::string phase_wechsler() {
/*
* Returns the extended Wechsler format for the current phase:
......@@ -541,8 +556,13 @@ namespace apg {
// Remove redundant '_0' suffices:
bwv.pop_back();
}
std::string s = wechslerise(bwv, bbox);
return ((s.length() > 1280) ? "#" : s);
if (isHexagonal()) {
std::string s = wechslerhex(bwv);
return ((s.length() > 1280) ? "#" : s);
} else {
std::string s = wechslerise(bwv, bbox);
return ((s.length() > 1280) ? "#" : s);
}
} else {
return "0";
}
......
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