Commit 2d88ef88 authored by Adam P. Goucher's avatar Adam P. Goucher

Improved separation for B0 and multistate rules

parent 1dd6edde
#pragma once
#define LIFELIB_VERSION "ll1.22"
#define LIFELIB_VERSION "ll1.23"
#include "bitbounds.h"
#include <stdint.h>
......
......@@ -391,7 +391,10 @@ namespace apg {
return clusters;
}
std::map<std::string, int64_t> census(std::vector<bitworld> &planes, std::string (*adv)(pattern)) {
// Forward declaration for co-recursive function:
// std::map<std::string, int64_t> census(pattern pat, int numgens, std::string (*adv)(pattern), bool recurse);
std::map<std::string, int64_t> census(std::vector<bitworld> &planes, std::string (*adv)(pattern), bool recurse) {
bitworld lrem = planes[0];
for (uint64_t i = 1; i < M; i++) {
......@@ -441,20 +444,34 @@ namespace apg {
auto it = decompositions.find(repr);
if (it != decompositions.end()) {
elements = it->second;
} else if ((M == 1) && (!b0)) {
// 2-state rule:
} else {
uint64_t period = cl2.ascertain_period();
if ((zoi.length() <= 2) && (period == 4) && ((cl2.dx != 0) || (cl2.dy != 0))) {
// Separating standard spaceships is considerably
// faster and more reliable with sss; only fall
// back on pbb if this fails:
elements = sss(cl2);
if ((M == 1) && (!b0)) {
// 2-state rule:
if ((zoi.length() <= 2) && (period == 4) && ((cl2.dx != 0) || (cl2.dy != 0))) {
// Separating standard spaceships is considerably
// faster and more reliable with sss; only fall
// back on pbb if this fails:
elements = sss(cl2);
}
if (elements.size() == 0) { elements = pseudoBangBang(cl2, 0); }
} else if (recurse) {
// We may have a constellation since we've bypassed PseudoBangBang.
// This tends to be problematic in B0 and Generations rules with
// infinite-growth patterns, so we try to reseparate the pattern:
uint64_t period = cl2.ascertain_period();
std::map<std::string, int64_t> rc = census(cl2, period << 3, 0, false);
for (auto it2 = rc.begin(); it2 != rc.end(); ++it2) {
if (it2->second > 0) {
for (int64_t i = 0; i < it2->second; i++) {
elements.push_back(it2->first);
}
}
}
} else {
// PseudoBangBang not supported for multistate rules; skip separation:
elements.push_back(repr);
}
if (elements.size() == 0) { elements = pseudoBangBang(cl2, 0); }
decompositions[repr] = elements;
} else {
// PseudoBangBang not supported for multistate rules; skip separation:
elements.push_back(repr);
decompositions[repr] = elements;
}
} else {
......@@ -472,6 +489,10 @@ namespace apg {
return tally;
}
std::map<std::string, int64_t> census(std::vector<bitworld> &planes, std::string (*adv)(pattern)) {
return census(planes, adv, true);
}
std::map<std::string, int64_t> census(bitworld &live, bitworld &env, std::string (*adv)(pattern)) {
std::vector<bitworld> bwv;
bwv.push_back(live); bwv.push_back(env);
......@@ -482,13 +503,17 @@ namespace apg {
return census(live, env, 0);
}
std::map<std::string, int64_t> census(pattern pat, int numgens, std::string (*adv)(pattern)) {
std::map<std::string, int64_t> census(pattern pat, int numgens, std::string (*adv)(pattern), bool recurse) {
pattern hist(&lh, "", rule + "History");
hist += pat;
hist = hist[numgens];
std::vector<bitworld> bwv;
for (uint64_t i = 0; i <= M; i++) { bwv.push_back(hist.flatlayer(i)); }
return census(bwv, adv);
return census(bwv, adv, recurse);
}
std::map<std::string, int64_t> census(pattern pat, int numgens, std::string (*adv)(pattern)) {
return census(pat, numgens, adv, true);
}
std::map<std::string, int64_t> census(pattern pat, int numgens) {
......
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