Commit 259c0125 authored by Adam P. Goucher's avatar Adam P. Goucher

Ensure LifeHistory RLE files are saved with Golly's state numbering

parent d16bc56d
Pipeline #54765842 passed with stages
in 7 minutes and 57 seconds
#ifndef LIFELIB_VERSION /*
__version__=[x.replace('"', '') for x in '''
*/
#define LIFELIB_VERSION "ll2.2.5"
#define LIFELIB_VERSION "ll2.2.6"
// '''.split() if ('ll' in x)][0][2:]
#endif
......@@ -198,13 +198,16 @@ namespace apg {
void write_rle(std::ostream &outstream, hypernode<I> hnode, std::string rule) {
outstream << "#CLL state-numbering golly" << std::endl;
if (hnode.index == 0) {
outstream << "x = 1, y = 1, rule = " << gollyrule(rule) << std::endl;
outstream << state2string(0) << "!" << std::endl;
outstream << "b!" << std::endl;
} else {
RuleMapper* grm = getMapper(rule);
int linelength = 0;
std::map<std::pair<uint64_t, uint64_t>, uint64_t> cells;
......@@ -234,7 +237,7 @@ namespace apg {
for (auto it = cells.begin(); it != cells.end(); ++it) {
uint64_t y = it->first.first - miny;
uint64_t x = it->first.second - minx;
uint64_t c = it->second;
uint64_t c = grm->ll_to_golly(it->second);
if ((y > lasty) || (x > lastx) || (c != lastc)) {
printrun(outstream, runlength, state2string(lastc), linelength);
......@@ -255,6 +258,8 @@ namespace apg {
printrun(outstream, runlength, state2string(lastc), linelength);
outstream << "!" << std::endl;
delete grm;
}
}
......
......@@ -435,6 +435,26 @@ class Pattern(object):
# include it as an alias for Pattern.write_file():
save = write_file
def rle_string(self, filename=None, autoremove=True):
if filename is None:
filename = self.session.newfloat('pattern') + '.rle'
self.write_rle(filename)
with open(filename, 'rb') as f:
rs = regstring(f.read())
if autoremove:
try:
os.remove(filename)
except OSError:
pass
return rs
def viewer(self, filename=None, width=480, height=480, base64=True,
lv_config='#C [[ THEME 6 GRID GRIDMAJOR 0 ]]', autoremove=True):
......
......@@ -45,7 +45,7 @@ $3b3o3b2o3b2o3bo2bo7bo2bo12b3o$3bo2bo2b2o3b2o2bo3bo7bob2o12bo2bo$3bo
def test_lhistory(self):
scorbie = self.lt.pattern('''x = 50, y = 72, rule = LifeHistory
scstring = '''x = 50, y = 72, rule = LifeHistory
26.4B$25.4B$24.4B$19.3B.4B$18.8B10.E$18.7B.B7.3E$18.10B5.E$16.12B5.CE
$15.14B.5B$15.18B$14.22B$14.23B$12.ECB.22B$11.E.EB.23B$11.E4.22B$10.
2E5.20B$18.19B$17.21B$15.ECB.15B.4B$14.E.EB3.10B5.4B$14.E6.10B6.4B$
......@@ -55,11 +55,18 @@ $15.14B.5B$15.18B$14.22B$14.23B$12.ECB.22B$11.E.EB.23B$11.E4.22B$10.
6B4.2E.3E$21.6B6.B4.E$21.7B3.B2CB3E$8.3B11.8B.B2C.E$7.6B9.10B$5.11B5.
3B2C6B$5.10B2E5.2B2C6B$5.11BE5.10B$5.11BEBEB2.11B$5.12BECB.12B$5.13B.
15B$5.11B3.16B$5.11B3.16B.2B$5.10B4.18BCE$5.6B7.17B.BCE$5.6B6.4B2.8B.
4B.B$5.4B7.4B4.7B$5.3B7.4B5.6B$6.B7.4B6.4B$13.4B5.E3B$12.4B5.E.CB$11.
4B6.E.C$10.3AB8.E$9.3BA6.3E$8.3BA7.E$7.4B$6.4B$5.4B$4.4B$3.4B$2.4B$.
4B$4B$3B$2B!''')
4B.B$5.4B7.4B4.7B$5.3B7.4B5.6B$6.B7.3DB6.4B$13.3BD5.E3B$12.3BD5.E.CB$
11.4B6.E.C$10.3AB8.E$9.3BA6.3E$8.3BA7.E$7.4B$6.4B$5.4B$4.4B$3.4B$2.4B
$.4B$4B$3B$2B!'''
scorbie = self.lt.pattern(scstring)
self.assertEqual(scorbie[2000].population, 4425)
rlestring = scorbie.rle_string()
scstring = scstring.replace('\n','').split('tory')[-1]
rlestring = rlestring.replace('\n','').split('tory')[-1]
self.assertEqual(scstring, rlestring)
def test_stream(self):
......
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