Commit 4d2e11b3 authored by Adam P. Goucher's avatar Adam P. Goucher

Hexagonal rules

parent 95b06ec5
Pipeline #38624045 passed with stage
in 3 minutes and 15 seconds
......@@ -7,10 +7,12 @@ genus_list = []
genus_list.append({'name': 'b3s23life', 'regex': 'b3s23'})
genus_list.append({'name': 'lifelike', 'regex': 'b0?1?2?3?4?5?6?7?8?s0?1?2?3?4?5?6?7?8?'})
genus_list.append({'name': 'generations', 'regex': 'g[1-9][0-9]*b1?2?3?4?5?6?7?8?s0?1?2?3?4?5?6?7?8?'})
genus_list.append({'name': 'isotropic', 'regex': 'b[1-9ceaiknjqrytwz-]*s[0-9ceaiknjqrytwz-]*'})
genus_list.append({'name': 'isotropic', 'regex': 'b[1-8ceaiknjqrytwz-]*s[0-8ceaiknjqrytwz-]*'})
genus_list.append({'name': 'isotropic', 'regex': 'b[1-6omp-]*s[0-6omp-]*h'}) # Hexagonal rules
genus_list.append({'name': 'ltl', 'regex': 'r[234567]b[1-9][0-9]*t[1-9][0-9]*s[1-9][0-9]*t[1-9][0-9]*'})
genus_list.append({'name': 'gltl', 'regex': 'g[1-9][0-9]*r[234567]b[1-9][0-9]*t[1-9][0-9]*s[1-9][0-9]*t[1-9][0-9]*'})
genus_list.append({'name': 'isogeny', 'regex': 'g[1-9][0-9]*b[1-9ceaiknjqrytwz-]*s[0-9ceaiknjqrytwz-]*'})
genus_list.append({'name': 'isogeny', 'regex': 'g[1-9][0-9]*b[1-8ceaiknjqrytwz-]*s[0-8ceaiknjqrytwz-]*'})
genus_list.append({'name': 'isogeny', 'regex': 'g[1-9][0-9]*b[1-6omp-]*s[0-6omp-]*h'}) # Hexagonal rules
genus_list.append({'name': 'bsfkl', 'regex': 'b1?2?3?4?5?6?7?8?s0?1?2?3?4?5?6?7?8?f0?1?2?3?4?5?6?7?8?k0?1?2?3?4?5?6?7?8?l0?1?2?3?4?5?6?7?8?'})
genus_list.append({'name': 'hrot', 'regex': 'r[2345]b[0-9a-f]*s[0-9a-f]*z?'})
genus_list.append({'name': 'ghrot', 'regex': 'g[1-9][0-9]*r[2345]b[0-9a-f]*s[0-9a-f]*z?'})
......@@ -21,7 +21,10 @@ def create_rule(rulestring):
f.write('}\n')
def str2tab(rulestring):
def str2tab(rulestring, hexagonal='unknown'):
if (hexagonal == 'unknown'):
hexagonal = (rulestring[-1].lower() == 'h')
isotrans = {}
centre = 0
......@@ -36,10 +39,13 @@ def str2tab(rulestring):
centre = 1
elif (c == '/'):
centre = 1 - centre
elif c in 'ceaiknjqrytwz-':
elif c in ('omp-' if hexagonal else 'ceaiknjqrytwz-'):
isotrans[(centre, lastloc)] += c
lord = "";
if not hexagonal:
lord += "_ceaccaieaeaknja_ceaccaieaeaknjaekejanaairerririekejanaairerriri";
lord += "ccknncqnaijaqnwaccknncqnaijaqnwakykkqyqjrtjnzrqakykkqyqjrtjnzrqa";
lord += "ekirkyrtejerkkjnekirkyrtejerkkjnekejjkrnejecjyccekejjkrnejecjycc";
......@@ -48,13 +54,29 @@ def str2tab(rulestring):
lord += "ccyyccyennkjyekeccyyccyennkjyekenykknejeirykrikenykknejeirykrike";
lord += "aqrznyirjwjqkkykaqrznyirjwjqkkykaqrqajiarqcnnkccaqrqajiarqcnnkcc";
lord += "intrneriaanajekeintrneriaanajekeajnkaeaeiaccaec_ajnkaeaeiaccaec_";
else:
prelord = "___o_moo" + "_pmmomoo" + "_mpmmpmm" + "ommpomo_";
prelord += prelord[::-1];
for i in range(512):
j = (i & 3) + ((i & 32) >> 3) + ((i & 256) >> 5) + ((i & 128) >> 3) + ((i & 8) << 2);
lord += prelord[j]
# raise NotImplementedError("Hexagonal rules are currently unsupported")
popcounts = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4]
lord2 = []
for i in range(512):
centre = (i >> 4) & 1
if hexagonal:
ncount = popcounts[(i & 443) & 15] + popcounts[(i & 443) >> 5]
else:
ncount = popcounts[i & 15] + popcounts[i >> 5]
if (centre, ncount) in isotrans:
fragment = isotrans[(centre, ncount)]
if (len(fragment) == 1):
......@@ -68,7 +90,11 @@ def str2tab(rulestring):
else:
lord2.append(0)
if hexagonal:
return lord2
rule_letters = {}
rule_letters[1] = "ce" ;
rule_letters[2] = "ceaikn" ;
rule_letters[3] = "ceaiknjqry" ;
......
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