Apgcode generation assumes the rule is isotropic, even when it isn't
I recently tried running apgluxe in testing mode with the ruletrees from here, which emulate a totalistic rule on the 12-neighbor triangular Moore neighborhood using a two-state ruletree, just to see if it would work. While this kind of worked, I noticed that some of the found objects had nonsensical apgcodes that didn't decode to the kind of object they were supposed to be.
A bit more testing and source-reading revealed that these objects were simply mirrored across one or both of the x and y axes. Since the two-state emulation rule is not isotropic (in fact, it's only invariant with respect to mirroring across one diagonal; mirroring across the other diagonal only works if the state bitplanes are also swapped), this mangled the patterns and broke them.
The problem seems to be in lifelib's wechslerise()
function (which is why I'm reporting this issue here), which applies all possible mirror and rotation transformation to the pattern and chooses the one with the shortest apgcode, without checking if those transformations are actually compatible with the rule. Indeed, commenting out all the incompatible transformations (i.e. everything but the first and the last) and recompiling stopped the bogus apgcodes from appearing.
Based on this, it looks like this is a general issue that affects all non-isotropic rules, not just the emulated TriLife rules I was testing.
In principle, lifelib should be able to automatically detect (either at compile time or at runtime) which transformations of the lattice are compatible with the given rule, simply by testing all neighborhoods to see if the transformation changes the next-generation state. The list of appropriate transformations could then be saved e.g. in a bitmask that could be easily checked when generating the apgcode. Done properly, this should also allow unifying the wechslerise()
and wechslerhex()
functions into a single function that works for both square and hexagonal neighborhoods.
If I have time, I might consider trying to do this myself and making a merge request. However, as I'm not sure I do, I felt it would be best to start by reporting the issue here.