Adapting Gencols
Posted: August 23rd, 2010, 12:56 pm
Paul Callahans 'Gencols' collision enumeration program is a useful utility, albeit tricky to master, but as with many utilities it has its limitations and these introduce a temptation to roll ones sleeves up and tweak the code. As a result I have made a number of modifications that make it more useful to me. I suspect others may have done so also. When I mentioned on the "Other rules" forum that I had adapted Gencols to handle CA rules other than Life, Ntsimp asked whether I would be willing to share the code. Well here it is in the attached file. [EDIT: anyone who downloaded gencols-pat-001.zip might want to download the latest file here. The original had a typo that affected periodicity detection]
I started this new topic in the hope that it would prompt other Gencols users to share the modifications they have made. Not necessarily the code: sometimes just a description of how to make the modification may be better, partlicularly if one already has a non-standard build.
For example, here is a recipe for adapting Gencols to handle rules other than Life. It assumes some C knowledge, because you are going to have to write some code yourself.
Step 1. Eliminate Life-specific fast generation code.
Edit the defs.h file and look for the line that says "#define USEBOXES 1" and comment it out.
Rebuild Gencols without boxes.c.
The result should run correctly, albeit slightly slower, and it will still only use the Life rule.
Step 2. Add the CA rule parser.
The file lists.c contains an array called rule and a function called gensparse() that uses it. Add a setrule(char *) function to populate this array from a rule string. If, as I did, you wish to handle more than just totalistic rules then you will need a larger array and will need to adapt gensparse() to handle this.
Step 3. Add the command line parameter
Open gencols.c and look for a long string of if .. else if constructs looking a bit like the line below. Somewhere in there insert
Rebuild gencols and now you can specify the rule on the command line by adding -rule myrulestring to the command line. I went a bit further than this and got Gencols to read rule strings from the pattern file and write them to output.
I started this new topic in the hope that it would prompt other Gencols users to share the modifications they have made. Not necessarily the code: sometimes just a description of how to make the modification may be better, partlicularly if one already has a non-standard build.
For example, here is a recipe for adapting Gencols to handle rules other than Life. It assumes some C knowledge, because you are going to have to write some code yourself.
Step 1. Eliminate Life-specific fast generation code.
Edit the defs.h file and look for the line that says "#define USEBOXES 1" and comment it out.
Rebuild Gencols without boxes.c.
The result should run correctly, albeit slightly slower, and it will still only use the Life rule.
Step 2. Add the CA rule parser.
The file lists.c contains an array called rule and a function called gensparse() that uses it. Add a setrule(char *) function to populate this array from a rule string. If, as I did, you wish to handle more than just totalistic rules then you will need a larger array and will need to adapt gensparse() to handle this.
Step 3. Add the command line parameter
Open gencols.c and look for a long string of if .. else if constructs looking a bit like the line below. Somewhere in there insert
Code: Select all
} else if (!strcmp(argv[argind],"-rule")) {
setrule(argv[++argind]);