Commit 6329050f authored by Adam P. Goucher's avatar Adam P. Goucher

Conservative determination of rule symmetries

parent ce2db752
Pipeline #55523310 failed with stages
in 1 minute and 49 seconds
#ifndef LIFELIB_VERSION /*
__version__=[x.replace('"', '') for x in '''
*/
#define LIFELIB_VERSION "ll2.2.7"
#define LIFELIB_VERSION "ll2.2.8"
// '''.split() if ('ll' in x)][0][2:]
#endif
......@@ -474,16 +474,19 @@ def generate_code(rules, clean_before=False):
f.write('namespace apg {\n\n')
# Function to convert rulestring to rule integer:
not_used = True
f.write(' std::string get_zoi(std::string rule) {\n')
for (fam, r) in zip(families, rules):
if (fam >= 6):
f.write(' if (rule == "%s") { return "%s"; }\n' % (r, genera.rule_property(r, 'zoi')))
not_used = False
if not_used:
f.write(' (void) rule;\n')
f.write(' return "99";\n')
f.write(' }\n\n')
for prop in ['zoi', 'syms']:
not_used = True
f.write(' std::string get_%s(std::string rule) {\n' % prop)
for (fam, r) in zip(families, rules):
if (fam >= 6):
f.write(' if (rule == "%s") { return "%s"; }\n' % (r, genera.rule_property(r, prop)))
not_used = False
if not_used:
f.write(' (void) rule;\n')
f.write(' return "99";\n')
f.write(' }\n\n')
# Function to convert rulestring to rule integer:
f.write(' int rule2int(std::string rule) {\n')
......
......@@ -8,6 +8,11 @@ namespace apg {
return "99";
}
std::string get_syms(std::string rule) {
(void) rule;
return "99";
}
int rule2int(std::string rule) {
if (rule == "b3s23") { return 0; }
return -1;
......
......@@ -758,6 +758,12 @@ namespace apg {
return rep;
}
std::string wechslernone(std::vector<bitworld> &bwv, int64_t *rect) {
return comprep(rep, canonise_orientation(bwv, rect[2], rect[3], rect[0], rect[1], 1, 0, 0, 1));
}
std::string wechslerise(std::vector<bitworld> &bwv, int64_t *rect) {
std::string rep = "#";
......
......@@ -2,6 +2,16 @@
import os
from .rulefiles import rules_dir
def syms(rulestring):
filename = rulestring if (rulestring[0] == 'x') else ('x' + rulestring)
with open(os.path.join(rules_dir, filename + '.h')) as f:
for line in f:
if 'SYMS="' in line:
return line.split('"')[1]
return "NONE"
def zoi(rulestring):
filename = rulestring if (rulestring[0] == 'x') else ('x' + rulestring)
......
from .parsetable import ReadRuleTable
from .parsetree import ReadRuleTree, SurplusTreeError, FlattenRuleTree
from .parsetree import ReadRuleTree, SurplusTreeError, FlattenRuleTree, get_symmetries
from .writetree import TransitionsToTree
from .writecode import NodesToCode, MakeStaticTable
......@@ -32,6 +32,15 @@ def analyse_tree(segments):
print('Reading rule tree...')
n_states, nhood, list_of_nodes = ReadRuleTree(lines)
syms = get_symmetries(n_states, nhood, list_of_nodes)
print('Symmetries: %s' % syms)
if len(syms) == 12:
symstring = "HEXAGONAL"
elif len(syms) == 8:
symstring = "SQUARE"
else:
symstring = "NONE"
is16bit = (n_states > 256)
......@@ -50,6 +59,7 @@ def analyse_tree(segments):
preamble += ['/* ZOI="%s" */\n' % zoi]
preamble += ['/* BITS="%d" */\n' % (16 if is16bit else 8)]
preamble += ['/* NHOOD="%s" */\n' % nhood]
preamble += ['/* SYMS="%s" */\n' % symstring]
segments['@PREAMBLE'] = preamble
......
......@@ -527,22 +527,27 @@ namespace apg {
return dt;
}
bool isHexagonal() {
std::string rule_symmetries() {
std::string rule = rulestring;
if (rule.length() == 0) { return false; }
if (rule.length() == 0) { return "NONE"; }
// Remove history suffix:
if ((rule.length() >= 8) && (rule.substr(rule.length() - 6) == "istory")) {
rule = rule.substr(0, rule.length() - 7);
}
std::string syms = get_syms(rule);
// Match uppercase 'H' and lowercase 'h':
return (((int) rule[rule.length() - 1]) & 31) == 8;
if (syms == "99") {
syms = ((((int) rule[rule.length() - 1]) & 31) == 8) ? "HEXAGONAL" : "SQUARE";
}
return syms;
}
std::string phase_wechsler() {
std::string phase_wechsler(std::string syms) {
/*
* Returns the extended Wechsler format for the current phase:
*/
......@@ -560,12 +565,16 @@ namespace apg {
// Remove redundant '_0' suffices:
bwv.pop_back();
}
if (isHexagonal()) {
if (syms == "HEXAGONAL") {
std::string s = wechslerhex(bwv);
return ((s.length() > 1280) ? "#" : s);
} else {
} else if (syms == "SQUARE") {
std::string s = wechslerise(bwv, bbox);
return ((s.length() > 1280) ? "#" : s);
} else {
std::string s = wechslernone(bwv, bbox);
return ((s.length() > 1280) ? "#" : s);
}
} else {
return "0";
......@@ -583,10 +592,12 @@ namespace apg {
uint64_t p = ascertain_period();
basepattern<I> x = advance(0);
std::string syms = rule_symmetries();
for (uint64_t t = 0; t < p; t++) {
if (t != 0) { x = x.advance((rulestring[1] == '0') ? 2 : 1); }
// rep = comprep(rep, x.flatlayer(0).wechsler());
rep = comprep(rep, x.phase_wechsler());
rep = comprep(rep, x.phase_wechsler(syms));
}
std::ostringstream ss;
......
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