Commit bf133dac authored by Adam P. Goucher's avatar Adam P. Goucher

Lifetree.unify() and Pattern.layers()

parent 5c27075a
Pipeline #60424493 canceled with stages
...@@ -302,6 +302,10 @@ class Pattern(object): ...@@ -302,6 +302,10 @@ class Pattern(object):
newptr = self.lifelib('GetOneCell', self.ptr) newptr = self.lifelib('GetOneCell', self.ptr)
return Pattern(self.session, newptr, self.owner) return Pattern(self.session, newptr, self.owner)
def layers(self):
return self.owner.deunify(self)
def components(self, halo='ooo$ooo$ooo!'): def components(self, halo='ooo$ooo$ooo!'):
ccs = [] ccs = []
......
...@@ -25,6 +25,23 @@ class Lifetree(object): ...@@ -25,6 +25,23 @@ class Lifetree(object):
session.lifetree_ptrs.add(self.ptr) session.lifetree_ptrs.add(self.ptr)
def unify(self, *patterns):
output = self.pattern()
for (i, pat) in enumerate(patterns):
this_layer = self.pattern()
this_layer += pat
output += (this_layer << i)
return output
def deunify(self, pattern):
n = self.n_layers
return tuple([((pattern << (n - 1 - i)) >> (n - 1)) for i in range(n)])
def load(self, filename, compressed='deduce', tempfile='tempfile'): def load(self, filename, compressed='deduce', tempfile='tempfile'):
filename = os.path.abspath(filename) filename = os.path.abspath(filename)
......
...@@ -23,6 +23,14 @@ class TestGoL(unittest.TestCase): ...@@ -23,6 +23,14 @@ class TestGoL(unittest.TestCase):
self.assertEqual(((pd << 2) >> 2), pd) self.assertEqual(((pd << 2) >> 2), pd)
block = self.lt.pattern('xs4_33')
hwss = self.lt.pattern('xq4_27deee6')
mwss = self.lt.pattern('xq4_27dee6')
combined = self.lt.unify(block, pd, hwss, mwss)
self.assertEqual(combined.wechsler, '33_4r4z4r4_27deee6_27dee6')
self.assertEqual(combined.layers(), (block, pd, hwss, mwss)
def test_ulimit(self): def test_ulimit(self):
self.sess.lifelib.ensure_limit(10000, 1) self.sess.lifelib.ensure_limit(10000, 1)
......
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