Just created a 3-State INT rule generator! The rulestrings in the output file use the notation described
here.
Note that these rulestrings can get
long. A quick calculation I did indicated that the maximum possible length for a rulestring is over 10,000 characters! Since rulestrings over 1,000 characters in length are common, the log file this creates can get pretty big.
Like with my other rule generators, this also creates a log file and a config file.
Code: Select all
import random
import string
import os
import golly
from distutils import util
ruleStructure = [[0,["",["","",None,"00000000","00000000"]]],[1,["c",["1c","0",None,"00000001","00000002"]],["e",["1e","0",None,"00000010","00000020"]]],[2,["c",["2c","0",None,"00000101","00000202"],["1c","1c",None,"00000102","00000201"]],["e",["2e","0",None,"00001010","00002020"],["1e","1e",None,"00001020","00002010"]],["k",["2k","0",None,"00001001","00002002"],["1e","1c",None,"00001002","00002001"]],["a",["2a","0",None,"00000011","00000022"],["1e","1c",None,"00000012","00000021"]],["i",["2i","0",None,"00100010","00200020"],["1e","1e",None,"00100020","00200010"]],["n",["2n","0",None,"00010001","00020002"],["1c","1c",None,"00010002","00020001"]]],[3,["c",["3c","0",None,"00010101","00020202"],["2n","1c",None,"00010201","00020102"],["2c","1c",None,"00010102","00020201"]],["e",["3e","0",None,"00101010","00202020"],["2i","1c",None,"00102010","00201020"],["2e","1e",None,"00101020","00202010"]],["k",["3k","0",None,"00101001","00202002"],["2e","1c",None,"00101002","00202001"],["2k","1e",None,"00102001","00201002"]],["a",["3a","0",None,"00001110","00002220"],["2e","1c",None,"00001210","00002120"],["2a","1e",None,"00001120","00002210"]],["i",["3i","0",None,"00000111","00000222"],["2a","1c",None,"00000112","00000221"],["2c","1e",None,"00000121","00000212"]],["n",["3n","0",None,"00001101","00002202"],["2a","1c",None,"00001102","00002201"],["2k","1c",None,"00001201","00002102"],["2c","1e",None,"00002101","00001202"]],["y",["3y","0",None,"00100101","00200202"],["2k","1c",None,"00100102","00200201"],["2c","1e",None,"00200101","00100202"]],["q",["3q","0",None,"00010011","00020022"],["2a","1c",None,"00020011","00010022"],["2k","1c",None,"00010012","00020021"],["2n","1e",None,"00010021","00020012"]],["j",["3j","0",None,"00001011","00002022"],["2e","1c",None,"00001012","00002021"],["2a","1e",None,"00002011","00001022"],["2k","1e",None,"00001021","00002012"]],["r",["3r","0",None,"00100011","00200022"],["2i","1c",None,"00100012","00200021"],["2a","1e",None,"00200011","00100022"],["2k","1e",None,"00100021","00200012"]]],[4,["c",["4c","0",None,"01010101","02020202"],["3c","1c",None,"01010102","02020201"],["2c","2c",None,"01010202","02020101"],["2n","2n",None,"01020102","02010201"]],["e",["4e","0",None,"10101010","20202020"],["3e","1e",None,"10101020","20202010"],["2e","2e",None,"10102020","20201010"],["2i","2i",None,"10201020","20102010"]],["k",["4k","0",None,"00101101","00202202"],["3j","1c",None,"00101102","00202201"],["3k","1c",None,"00101201","00202102"],["3y","1e",None,"00102101","00201202"],["3n","1e",None,"00201101","00102202"],["2e","2c",None,"00101202","00202101"],["2k","2k$",None,"00102102","00201201"],["2k","2a",None,"00102201","00201102"]],["a",["4a","0",None,"00001111","00002222"],["3j","1c",None,"00001211","00002122"],["3a","1c",None,"00001112","00002221"],["3n","1e",None,"00001121","00002212"],["3i","1e",None,"00002111","00001222"],["2e","2c",None,"00001212","00002121"],["2a","2a$",None,"00001122","00002211"],["2k","2a",None,"00001221","00002112"]],["i",["4i","0",None,"00110110","00220220"],["3r","1c",None,"00110210","00220120"],["3n","1e",None,"00110120","00220210"],["2i","2c",None,"00120210","00210120"],["2k","2k",None,"00120120","00210210"],["2a","2a",None,"00110220","00220110"]],["n",["4n","0",None,"00010111","00020222"],["3q","1c",None,"00010211","00020122"],["3n","1c",None,"00010112","00020221"],["3i","1c",None,"00020111","00010222"],["3c","1e",None,"00010121","00020212"],["2k","2c",None,"00010212","00020121"],["2n","2a",None,"00010221","00020112"],["2c","2a",None,"00010122","00020211"]],["y",["4y","0",None,"00110101","00220202"],["3q","1c",None,"00110201","00220102"],["3y","1c",None,"00120101","00210202"],["3n","1c",None,"00110102","00220201"],["3c","1e",None,"00210101","00120202"],["2a","2c",None,"00110202","00220101"],["2k","2c",None,"00120201","00210102"],["2k","2n",None,"00120102","00210201"]],["q",["4q","0",None,"00111001","00222002"],["3a","1c",None,"00111002","00222001"],["3k","1c",None,"00121001","00212002"],["3q","1e",None,"00112001","00221002"],["2a","2k",None,"00112002","00221001"],["2e","2n",None,"00121002","00212001"]],["j",["4j","0",None,"00101011","00202022"],["3e","1c",None,"00101012","00202021"],["3r","1e",None,"00102011","00201022"],["3j","1e",None,"00201011","00102022"],["3k","1e",None,"00101021","00202012"],["2k","2e",None,"00102021","00201012"],["2i","2k",None,"00102012","00201021"],["2e","2a",None,"00101022","00202011"]],["r",["4r","0",None,"00101110","00202220"],["3e","1c",None,"00101210","00202120"],["3r","1e",None,"00102110","00201220"],["3j","1e",None,"00101120","00202210"],["3a","1e",None,"00201110","00102220"],["2k","2e",None,"00102120","00201210"],["2i","2a",None,"00102210","00201120"],["2e","2a",None,"00101220","00202110"]],["t",["4t","0",None,"00100111","00200222"],["3r","1c",None,"00100112","00200221"],["3y","1e",None,"00100121","00200212"],["3i","1e",None,"00200111","00100222"],["2i","2c",None,"00100212","00200121"],["2k","2a",None,"00100122","00200211"]],["w",["4w","0",None,"00011011","00022022"],["3j","1c",None,"00011012","00022021"],["3q","1e",None,"00011021","00022012"],["2n","2e",None,"00012021","00021012"],["2k","2k",None,"00012012","00021021"],["2a","2a",None,"00011022","00022011"]],["z",["4z","0",None,"00110011","00220022"],["3r","1c",None,"00110012","00220021"],["3q","1e",None,"00110021","00220012"],["2k","2k",None,"00120021","00210012"],["2a","2a",None,"00110022","00220011"],["2i","2n",None,"00120012","00210021"]]],[5,["c",["5c","0",None,"10101011","20202022"],["4e","1c",None,"10101012","20202021"],["4r","1e",None,"10102011","20201022"],["4j","1e",None,"10101021","20202012"],["3j","2e",None,"10102021","20201012"],["3a","2e",None,"10202011","20101022"],["3k","2e",None,"20101021","10202012"],["3e","2k",None,"10102012","20201021"],["3e","2a",None,"10101022","20202011"],["3r","2i",None,"10201021","20102012"]],["e",["5e","0",None,"01010111","02020222"],["4y","1c",None,"01010112","02020221"],["4n","1c",None,"02010111","01020222"],["4c","1e",None,"01010121","02020212"],["3y","2c",None,"01010212","02020121"],["3n","2c",None,"02010112","01020221"],["3i","2c",None,"02020111","01010222"],["3c","2k",None,"02010121","01020212"],["3c","2a",None,"01010122","02020211"],["3q","2n",None,"01020112","02010221"]],["k",["5k","0",None,"01011011","02022022"],["4w","1c",None,"02011011","01022022"],["4k","1c",None,"01011012","02022021"],["4y","1e",None,"01011021","02022012"],["3j","2c",None,"02021011","01012022"],["3c","2e",None,"01012021","02021012"],["3q","2k",None,"02012011","01021022"],["3y","2k",None,"01012012","02021021"],["3n","2a",None,"01011022","02022011"],["3k","2n",None,"01021012","02012021"]],["a",["5a","0",None,"00011111","00022222"],["4w","1c",None,"00011211","00022122"],["4a","1c",None,"00011112","00022221"],["4n","1e",None,"00011121","00022212"],["3j","2c",None,"00011212","00022121"],["3c","2e",None,"00012121","00021212"],["3n","2k",None,"00012112","00021221"],["3q","2a",None,"00011221","00022112"],["3i","2a",None,"00011122","00022211"],["3a","2n",None,"00021112","00012221"]],["i",["5i","0",None,"00111110","00222220"],["4r","1c",None,"00111210","00222120"],["4i","1e",None,"00112110","00221220"],["4a","1e",None,"00111120","00222210"],["3e","2c",None,"00121210","00212120"],["3n","2e",None,"00112120","00221210"],["3j","2k",None,"00121120","00212210"],["3r","2a",None,"00112210","00221120"],["3a","2a",None,"00111220","00222110"],["3i","2i",None,"00211120","00122210"]],["n",["5n","0",None,"00101111","00202222"],["4r","1c",None,"00101112","00202221"],["4j","1c",None,"00101211","00202122"],["4t","1e",None,"00102111","00201222"],["4a","1e",None,"00201111","00102222"],["4k","1e",None,"00101121","00202212"],["3e","2c",None,"00101212","00202121"],["3y","2e",None,"00102121","00201212"],["3i","2e",None,"00202111","00101222"],["3r","2k",None,"00102112","00201221"],["3j","2k",None,"00201211","00102122"],["3a","2k",None,"00201112","00102221"],["3r","2a",None,"00102211","00201122"],["3j","2a",None,"00101122","00202211"],["3k","2a",None,"00101221","00202112"],["3n","2i",None,"00201121","00102212"]],["y",["5y","0",None,"01101011","02202022"],["4j","1c",None,"01101012","02202021"],["4i","1e",None,"01102011","02201022"],["4k","1e",None,"01101021","02202012"],["3e","2c",None,"02101012","01202021"],["3n","2e",None,"01102021","02201012"],["3r","2k",None,"01102012","02201021"],["3k","2k",None,"01201012","02102021"],["3j","2a",None,"01101022","02202011"],["3y","2i",None,"01201021","02102012"]],["q",["5q","0",None,"00111011","00222022"],["4r","1c",None,"00111012","00222021"],["4j","1c",None,"00121011","00212022"],["4z","1e",None,"00112011","00221022"],["4w","1e",None,"00211011","00122022"],["4q","1e",None,"00111021","00222012"],["3q","2e",1,"00112021","00221012"],["3q","2e",2,"00212011","00121022"],["3r","2k",None,"00112012","00221021"],["3j","2k",None,"00211012","00122021"],["3k","2k",None,"00121021","00212012"],["3r","2a",None,"00122011","00211022"],["3j","2a",None,"00221011","00112022"],["3a","2a",None,"00111022","00222011"],["3q","2i",None,"00211021","00122012"],["3e","2n",None,"00121012","00212021"]],["j",["5j","0",None,"00111101","00222202"],["4q","1c",None,"00111201","00222102"],["4a","1c",None,"00111102","00222201"],["4k","1c",None,"00121101","00212202"],["4y","1e",None,"00112101","00221202"],["4n","1e",None,"00211101","00122202"],["3a","2c",None,"00111202","00222101"],["3k","2c",None,"00121201","00212102"],["3c","2e",None,"00212101","00121202"],["3q","2k",None,"00211201","00122102"],["3n","2k",None,"00112102","00221201"],["3i","2k",None,"00211102","00122201"],["3q","2a",None,"00112201","00221102"],["3y","2a",None,"00122101","00211202"],["3n","2a",None,"00221101","00112202"],["3j","2n",None,"00121102","00212201"]],["r",["5r","0",None,"00110111","00220222"],["4z","1c",None,"00110211","00220122"],["4t","1c",None,"00120111","00210222"],["4i","1c",None,"00110112","00220221"],["4y","1e",None,"00110121","00220212"],["4n","1e",None,"00210111","00120222"],["3r","2c",1,"00110212","00220121"],["3r","2c",2,"00120211","00210122"],["3q","2k",None,"00210211","00120122"],["3y","2k",None,"00120121","00210212"],["3n","2k",None,"00210112","00120221"],["3q","2a",None,"00110221","00220112"],["3n","2a",None,"00110122","00220211"],["3i","2a",None,"00220111","00110222"],["3c","2i",None,"00210121","00120212"],["3r","2n",None,"00120112","00210221"]]],[6,["c",["6c","0",None,"10101111","20202222"],["5c","1c",None,"10101112","20202221"],["5y","1e",None,"10101121","20202212"],["5n","1e",None,"10102111","20201222"],["5i","1e",None,"10201111","20102222"],["4e","2c",None,"10101212","20202121"],["4a","2e",None,"20201111","10102222"],["4k","2e",None,"10102121","20201212"],["4r","2k",None,"10201112","20102221"],["4j","2k",None,"10102112","20201221"],["4r","2a",None,"10102211","20201122"],["4j","2a",None,"10101122","20202211"],["4t","2i",None,"20102111","10201222"],["4i","2i",None,"10201121","20102212"],["3j","3a",None,"10102221","20201112"],["3e","3i",None,"10101222","20202111"],["3e","3n",None,"10102212","20201121"],["3e","3y",None,"10201212","20102121"],["3k","3j",None,"10102122","20201211"],["3r","3r$",None,"10201122","20102211"]],["e",["6e","0",None,"01011111","02022222"],["5j","1c",None,"01011112","02022221"],["5a","1c",None,"02011111","01022222"],["5k","1c",None,"01011211","02022122"],["5e","1e",None,"01011121","02022212"],["4a","2c",None,"02021111","01012222"],["4k","2c",None,"01011212","02022121"],["4c","2e",None,"01012121","02021212"],["4y","2k",None,"01012112","02021221"],["4n","2k",None,"02012111","01021222"],["4y","2a",None,"01011221","02022112"],["4n","2a",None,"01011122","02022211"],["4w","2n",None,"02011211","01022122"],["4q","2n",None,"01021112","02012221"],["3k","3c",None,"01021212","02012121"],["3c","3a",None,"01012221","02021112"],["3n","3i",None,"01011222","02022111"],["3y","3n",None,"01012212","02021121"],["3q","3q$",None,"01021122","02012211"],["3c","3j",None,"01012122","02021211"]],["k",["6k","0",None,"01101111","02202222"],["5q","1c",None,"01101112","02202221"],["5y","1c",None,"01101211","02202122"],["5n","1c",None,"02101111","01202222"],["5r","1e",None,"01102111","02201222"],["5j","1e",None,"01201111","02102222"],["5k","1e",None,"01101121","02202212"],["4r","2c",None,"02101112","01202221"],["4j","2c",None,"01101212","02202121"],["4y","2e",None,"01102121","02201212"],["4n","2e",None,"01202111","02101222"],["4z","2k",None,"01102112","02201221"],["4t","2k",None,"02102111","01201222"],["4q","2k",None,"01201112","02102221"],["4k","2k",1,"01201211","02102122"],["4k","2k",2,"02101121","01202212"],["4w","2a",None,"01101122","02202211"],["4i","2a",None,"01102211","02201122"],["4a","2a",None,"02201111","01102222"],["4k","2a",None,"01101221","02202112"],["4y","2i",None,"01201121","02102212"],["4j","2n",None,"02101211","01202122"],["3c","3e",None,"01202121","02101212"],["3q","3k",None,"01202112","02101221"],["3n","3a",None,"01102221","02201112"],["3j","3i",None,"01101222","02202111"],["3r","3n",None,"01102212","02201121"],["3k","3y",None,"01201212","02102121"],["3r","3q",None,"02102211","01201122"],["3q","3j",None,"01102122","02201211"],["3n","3j",None,"01202211","02101122"],["3y","3r",None,"01201221","02102112"]],["a",["6a","0",None,"00111111","00222222"],["5q","1c",None,"00111211","00222122"],["5n","1c",None,"00121111","00212222"],["5i","1c",None,"00111112","00222221"],["5r","1e",None,"00112111","00221222"],["5j","1e",None,"00111121","00222212"],["5a","1e",None,"00211111","00122222"],["4r","2c",None,"00111212","00222121"],["4j","2c",None,"00121211","00212122"],["4y","2e",None,"00112121","00221212"],["4n","2e",None,"00212111","00121222"],["4w","2k",None,"00211211","00122122"],["4i","2k",None,"00112112","00221221"],["4a","2k",None,"00211112","00122221"],["4k","2k",None,"00121121","00212212"],["4z","2a",None,"00112211","00221122"],["4t","2a",None,"00122111","00211222"],["4q","2a",None,"00111221","00222112"],["4a","2a",1,"00111122","00222211"],["4a","2a",2,"00221111","00112222"],["4n","2i",None,"00211121","00122212"],["4r","2n",None,"00121112","00212221"],["3e","3c",None,"00121212","00212121"],["3q","3a",None,"00112221","00221112"],["3r","3i",None,"00122211","00211122"],["3a","3i",None,"00111222","00222111"],["3r","3n",None,"00112212","00221121"],["3k","3n",None,"00121221","00212112"],["3r","3q",None,"00122112","00211221"],["3j","3q",None,"00121122","00212211"],["3y","3j",None,"00122121","00211212"],["3n","3j",None,"00112122","00221211"]],["i",["6i","0",None,"01110111","02220222"],["5r","1c",None,"01110112","02220221"],["5e","1e",None,"01110121","02220212"],["4t","2c",None,"01110212","02220121"],["4i","2c",None,"01120211","02210122"],["4y","2k",None,"01120121","02210212"],["4n","2a",None,"01110122","02220211"],["4c","2i",None,"01210121","02120212"],["4z","2n",None,"01120112","02210221"],["3r","3c",None,"01120212","02210121"],["3i","3i",None,"01110222","02220111"],["3n","3n",None,"01120221","02210112"],["3y","3y",None,"01210212","02120121"],["3q","3q",None,"01120122","02210211"]],["n",["6n","0",None,"10111011","20222022"],["5c","1c",None,"10111012","20222021"],["5q","1e",None,"10111021","20222012"],["4w","2e",None,"10112021","20221012"],["4q","2e",None,"10212011","20121022"],["4j","2k",None,"10112012","20221021"],["4r","2a",None,"10111022","20222011"],["4z","2i",None,"10211021","20122012"],["4e","2n",None,"10121012","20212021"],["3q","3q",None,"10212012","20121021"],["3a","3a",None,"10222011","20111022"],["3e","3q",None,"10121022","20212011"],["3j","3j",None,"10112022","20221011"],["3r","3r",None,"10211022","20122011"]]],[7,["c",["7c","0",None,"10111111","20222222"],["6n","1c",None,"10111211","20222122"],["6c","1c",None,"10111112","20222221"],["6a","1e",None,"10211111","20122222"],["6k","1e",None,"10111121","20222212"],["5c","2c",None,"10111212","20222121"],["5j","2e",None,"10212111","20121222"],["5a","2e",None,"20211111","10122222"],["5k","2e",None,"10112121","20221212"],["5q","2k",None,"10211211","20122122"],["5y","2k",None,"10112112","20221221"],["5n","2k",None,"10211112","20122221"],["5q","2a",None,"10111221","20222112"],["5n","2a",None,"10111122","20222211"],["5i","2a",None,"10221111","20112222"],["5r","2i",None,"10211121","20122212"],["5c","2n",None,"10121112","20212221"],["4e","3c",None,"10121212","20212121"],["4y","3e",None,"10212121","20121212"],["4n","3e",None,"20212111","10121222"],["4w","3k",None,"20211211","10122122"],["4k","3k",None,"10212112","20121221"],["4w","3a",None,"10112221","20221112"],["4a","3a",None,"10222111","20111222"],["4r","3i",None,"10111222","20222111"],["4r","3n",None,"10221211","20112122"],["4j","3n",None,"10112212","20221121"],["4j","3y",None,"10211212","20122121"],["4r","3q",None,"20121112","10212221"],["4j","3q",None,"10121122","20212211"],["4q","3j",None,"10212211","20121122"],["4a","3j",None,"20221111","10112222"],["4k","3j",None,"10112122","20221211"],["4z","3r",None,"10211221","20122112"],["4t","3r",None,"10211122","20122211"],["4i","3r",None,"10221121","20112212"]],["e",["7e","0",None,"01111111","02222222"],["6a","1c",None,"01111112","02222221"],["6k","1c",None,"01111211","02222122"],["6i","1e",None,"01112111","02221222"],["6e","1e",None,"01111121","02222212"],["5y","2c",None,"01121211","02212122"],["5n","2c",None,"01111212","02222121"],["5i","2c",None,"02111112","01222221"],["5e","2e",None,"01112121","02221212"],["5r","2k",None,"01112112","02221221"],["5j","2k",None,"01211112","02122221"],["5k","2k",None,"01121121","02212212"],["5r","2a",None,"01112211","02221122"],["5j","2a",None,"01111221","02222112"],["5a","2a",None,"01111122","02222211"],["5e","2i",None,"01211121","02122212"],["5q","2n",None,"01121112","02212221"],["4r","3c",None,"02121112","01212221"],["4j","3c",None,"01121212","02212121"],["4c","3e",None,"01212121","02121212"],["4y","3k",None,"01212112","02121221"],["4n","3a",None,"01112221","02221112"],["4i","3i",None,"01122211","02211122"],["4a","3i",None,"01111222","02222111"],["4t","3n",None,"01112212","02221121"],["4a","3n",None,"02211112","01122221"],["4k","3n",None,"01121221","02212112"],["4i","3y",None,"02112112","01221221"],["4k","3y",None,"01211212","02122121"],["4z","3q",None,"01122112","02211221"],["4w","3q",None,"01121122","02212211"],["4q","3q",None,"01221112","02112221"],["4y","3j",None,"01122121","02211212"],["4n","3j",None,"01112122","02221211"],["4y","3r",None,"01211221","02122112"],["4n","3r",None,"02211121","01122212"]]],[8,["",["8","0",None,"11111111","22222222"],["7c","1c",None,"11111112","22222221"],["7e","1e",None,"11111121","22222212"],["6c","2c",None,"11111212","22222121"],["6e","2e",None,"11112121","22221212"],["6k","2k",None,"11112112","22221221"],["6a","2a",None,"11111122","22222211"],["6i","2i",None,"11211121","22122212"],["6n","2n",None,"11121112","22212221"],["5c","3c",None,"11121212","22212121"],["5e","3e",None,"11212121","22121212"],["5k","3k",None,"11212112","22121221"],["5a","3a",None,"11112221","22221112"],["5i","3i",None,"11111222","22222111"],["5n","3n",None,"11112212","22221121"],["5y","3y",None,"11211212","22122121"],["5q","3q",None,"11121122","22212211"],["5j","3j",None,"11112122","22221211"],["5r","3r",None,"11211122","22122211"],["4e","4c",None,"12121212","21212121"],["4k","4k",None,"11212212","22121121"],["4a","4a",None,"11112222","22221111"],["4r","4n",None,"11121222","22212111"],["4y","4j",None,"11212122","22121211"],["4i","4t",None,"11211222","22122111"],["4q","4w",None,"11122122","22211211"],["4z","4z",None,"11221122","22112211"]]]]
#functions
def generate_config():
configstring = "#Execution Options (options for while Golly is running a rule)\n\t#Search Options\n\t\t#the number of searches to run for a rule\n"
configstring = configstring + "\t\tsearch_number = " + golly.getstring("Number of soups per rule searched:", "10")
configstring = configstring + "\n\n\t\t#the number of generations to run a search\n\t\tsearch_length = " + golly.getstring("Number of generations to run each soup:", "100")
configstring = configstring + "\n\n\t\t#stops searching a rule if its bounding box is expanding at c\n\t\t#searches take much less time if this is enabled\n\t\t#rules for which this activates won't have data beyond their name and the fact they tested positive for this check written in the log file\n\t\t"
cCheck = bool(int(golly.getstring("Do you want to skip the majority of calculations for rules that expand at c? (1=Y/0=N):", "1")))
configstring = configstring + "\n\t\tstop_run_at_c = " + str(cCheck)
if cCheck:
configstring = configstring + "\n\n\t\t\t#the generation at which to conduct the c check\n\t\t\t#higher values save less time, lower values are more likely to get false positives"
configstring = configstring + "\n\t\t\tc_check_when = " + golly.getstring("After how many generations should expansion rate be checked?","50")
configstring = configstring + "\n\n\t\t\t#an additional parameter needed for a c check to return positive\n\t\t\t#if the population density (calc: population/bounding box area) is greater than this value, it returns positive"
configstring = configstring + "\n\t\t\tc_density_check = " + golly.getstring("Above which density do you want c-expanding rules to be filtered out? (input a value between 0 and 1):", "0.1")
else:
configstring = configstring + "\n\n\t\t\t#the generation at which to conduct the c check\n\t\t\t#higher values save less time, lower values are more likely to get false positives\n\t\t\tc_check_when = 50\n\n\t\t\t#an additional parameter needed for a c check to return positive\n\t\t\t#if the population density (calc: population/bounding box area) is greater than this value, it returns positive\n\t\t\tc_density_check = 0.1"
configstring = configstring + "\n\n\t\t#otherwise, there is an option to stop running after exceeding a certain population\n\t\t#check is only executed if stop_run_at_c is false\n\t\t#only use this if you don't want to calculate data for exploding rules in general"
configstring = configstring + "\n\t\tpopulation_stop_check = false"
configstring = configstring + "\n\n\t\t\tstop_above_population = 15000\n\n#Classification Options\n\t#only starts checking for stability after a specific generation"
configstring = configstring + "\n\tstart_stability_check_after_gen = 50\n\n\t#classifies a rule as stable if its population has stopped changing by a specific generation\n\t#not affected by start_stability_check_after_gen"
configstring = configstring + "\n\tstability_change_gen = 50\n\n#Log Options (options for what should be printed to the log)\n\t#writes data collected for stable rules if true"
configstring = configstring + "\n\twrite_stable_data = true\n\n\t#writes data collected for exploding rules if true\n\twrite_exploding_data = true\n\n\t#writes data for (seemingly) chaotic rules if true\n\twrite_chaotic_data = true\n\n\t#writes the median population for every generation if true\n\twrite_median_population = true\n\n\t#writes the median population change (growth) for every generation if true\n\twrite_median_growth = true\n\n\t#writes the median growth change (acceleration) for every generation if true\n\twrite_median_acceleration = true\n\n\t#writes the median density for every generation if true\n\twrite_median_density = true\n\n\t#writes the summary of the data collected if true\n\twrite_data_summary = true"
configstring = configstring + "\n\n#visualize rules searched in golly\n#this is much slower than a normal search, so low settings are recommended\nvisualize = false\n\n-\n"
f = open("rulegenconfig_3StateINT.txt","w")
f.write(configstring)
f.close
def generate_rulestring():
ruleStruct = ruleStructure
changingFixedRandNums = random.randint(0,1) #changes every transition
changingFixedRandConfigs = random.randint(0,1) #changes every num
changingFixedRandSubconfigs = random.randint(0,1) #changes every config
fixedRandNums = random.uniform(0.1,0.9)
fixedRandNums2 = random.uniform(0.1,0.9)
fixedRandConfigs = random.uniform(0.1,0.9)
fixedRandSubconfigs = random.uniform(0.1,0.9)
rulestring = ""
transitions = ["BA","/BB","/TA","/TB","/SA","/SB"]
templist = []
for numbers in ruleStruct:
if random.random() < fixedRandNums:
transitions[0] = transitions[0] + str(numbers[0])
transitions[1] = transitions[1] + str(numbers[0])
for configs in numbers:
if isinstance(configs,int):
continue
if random.random() < fixedRandConfigs:
transitions[0] = transitions[0] + configs[0]
transitions[1] = transitions[1] + configs[0]
for subconfigs in configs:
if isinstance(subconfigs,str):
continue
if random.random() < fixedRandSubconfigs:
if random.random() < fixedRandNums2:
transitions[0] = transitions[0] + "(" + subconfigs[0] + subconfigs[1] + ")"
if subconfigs[2] != None:
transitions[0] = transitions[0] + "[" + str(subconfigs[2]) + "]"
else:
transitions[1] = transitions[1] + "(" + subconfigs[0] + subconfigs[1] + ")"
if subconfigs[2] != None:
transitions[1] = transitions[1] + "[" + str(subconfigs[2]) + "]"
if random.random() < fixedRandSubconfigs and subconfigs[0] != subconfigs[1]:
if random.random() < fixedRandNums2:
transitions[0] = transitions[0] + "(" + subconfigs[1] + subconfigs[0] + ")"
if subconfigs[2] != None:
transitions[0] = transitions[0] + "[" + str(subconfigs[2]) + "]"
else:
transitions[1] = transitions[1] + "(" + subconfigs[1] + subconfigs[0] + ")"
if subconfigs[2] != None:
transitions[1] = transitions[1] + "[" + str(subconfigs[2]) + "]"
if changingFixedRandSubconfigs == 1:
fixedRandSubconfigs = random.uniform(0.1,0.9)
if changingFixedRandConfigs == 1:
fixedRandConfigs = random.uniform(0.1,0.9)
if changingFixedRandNums == 1:
fixedRandNums = random.uniform(0.1,0.9)
fixedRandNums2 = random.uniform(0.1,0.9)
for numbers in ruleStruct:
if random.random() < fixedRandNums:
transitions[2] = transitions[2] + str(numbers[0])
transitions[4] = transitions[4] + str(numbers[0])
for configs in numbers:
if isinstance(configs,int):
continue
if random.random() < fixedRandConfigs:
transitions[2] = transitions[2] + configs[0]
transitions[4] = transitions[4] + configs[0]
for subconfigs in configs:
if isinstance(subconfigs,str):
continue
if random.random() < fixedRandSubconfigs:
if random.random() < fixedRandNums2:
transitions[2] = transitions[2] + "(" + subconfigs[0] + subconfigs[1] + ")"
if subconfigs[2] != None:
transitions[2] = transitions[2] + "[" + str(subconfigs[2]) + "]"
else:
transitions[4] = transitions[4] + "(" + subconfigs[0] + subconfigs[1] + ")"
if subconfigs[2] != None:
transitions[4] = transitions[4] + "[" + str(subconfigs[2]) + "]"
if random.random() < fixedRandSubconfigs and subconfigs[0] != subconfigs[1]:
if random.random() < fixedRandNums2:
transitions[2] = transitions[2] + "(" + subconfigs[1] + subconfigs[0] + ")"
if subconfigs[2] != None:
transitions[2] = transitions[2] + "[" + str(subconfigs[2]) + "]"
else:
transitions[4] = transitions[4] + "(" + subconfigs[1] + subconfigs[0] + ")"
if subconfigs[2] != None:
transitions[4] = transitions[4] + "[" + str(subconfigs[2]) + "]"
if changingFixedRandSubconfigs == 1:
fixedRandSubconfigs = random.uniform(0.1,0.9)
if changingFixedRandConfigs == 1:
fixedRandConfigs = random.uniform(0.1,0.9)
if changingFixedRandNums == 1:
fixedRandNums = random.uniform(0.1,0.9)
fixedRandNums2 = random.uniform(0.1,0.9)
for numbers in ruleStruct:
if random.random() < fixedRandNums:
transitions[3] = transitions[3] + str(numbers[0])
transitions[5] = transitions[5] + str(numbers[0])
for configs in numbers:
if isinstance(configs,int):
continue
if random.random() < fixedRandConfigs:
transitions[3] = transitions[3] + configs[0]
transitions[5] = transitions[5] + configs[0]
for subconfigs in configs:
if isinstance(subconfigs,str):
continue
if random.random() < fixedRandSubconfigs:
if random.random() < fixedRandNums2:
transitions[3] = transitions[3] + "(" + subconfigs[0] + subconfigs[1] + ")"
if subconfigs[2] != None:
transitions[3] = transitions[3] + "[" + str(subconfigs[2]) + "]"
else:
transitions[5] = transitions[5] + "(" + subconfigs[0] + subconfigs[1] + ")"
if subconfigs[2] != None:
transitions[5] = transitions[5] + "[" + str(subconfigs[2]) + "]"
if random.random() < fixedRandSubconfigs and subconfigs[0] != subconfigs[1]:
if random.random() < fixedRandNums2:
transitions[3] = transitions[3] + "(" + subconfigs[1] + subconfigs[0] + ")"
if subconfigs[2] != None:
transitions[3] = transitions[3] + "[" + str(subconfigs[2]) + "]"
else:
transitions[5] = transitions[5] + "(" + subconfigs[1] + subconfigs[0] + ")"
if subconfigs[2] != None:
transitions[5] = transitions[5] + "[" + str(subconfigs[2]) + "]"
if changingFixedRandSubconfigs == 1:
fixedRandSubconfigs = random.uniform(0.1,0.9)
if changingFixedRandConfigs == 1:
fixedRandConfigs = random.uniform(0.1,0.9)
if changingFixedRandNums == 1:
fixedRandNums = random.uniform(0.1,0.9)
fixedRandNums2 = random.uniform(0.1,0.9)
if transitions[0][:3] == "BA0":
transitions[0] = transitions[0][:2] + transitions[0][3:]
if transitions[0][:4] == "BA()":
transitions[0] = transitions[0][:2] + transitions[0][4:]
if transitions[1][:4] == "/BB0":
transitions[1] = transitions[1][:3] + transitions[1][4:]
if transitions[1][:5] == "/BB()":
transitions[1] = transitions[1][:3] + transitions[1][5:]
if transitions[2][:6] == "/TA0()":
transitions[2] = transitions[2][:4] + transitions[2][6:]
if transitions[2][:5] == "/TA()":
transitions[2] = transitions[2][:3] + transitions[2][5:]
if transitions[3][:6] == "/TB0()":
transitions[3] = transitions[3][:4] + transitions[3][6:]
if transitions[3][:5] == "/TB()":
transitions[3] = transitions[3][:3] + transitions[3][5:]
if transitions[4][:6] == "/SA0()":
transitions[4] = transitions[4][:4] + transitions[4][6:]
if transitions[4][:5] == "/SA()":
transitions[4] = transitions[4][:3] + transitions[4][5:]
if transitions[5][:6] == "/SB0()":
transitions[5] = transitions[5][:4] + transitions[5][6:]
if transitions[5][:5] == "/SB()":
transitions[5] = transitions[5][:3] + transitions[5][5:]
charlist = ["c","e","k","a","i","n","y","q","j","r","t","w","z"]
numlist = ["1","2","3","4","5","6","7","8"]
index = 0
charIndex = 0
includeChar = True
tempStr = ""
for t in transitions:
for c in t:
for d in charlist:
if c == d:
if charIndex + 1 >= len(t) and t[charIndex - 2] != "(":
includeChar = False
elif charIndex + 2 >= len(t) and t[charIndex - 2] != "(" and t[charIndex + 1] != "(" and t[charIndex + 1] != "$" and t[charIndex + 1] != ")":
includeChar = False
elif charIndex + 3 >= len(t) and t[charIndex - 2] != "(" and t[charIndex + 1] != "(" and t[charIndex + 1] != "$" and t[charIndex + 1] != ")" and t[charIndex + 2] != ")":
includeChar = False
elif t[charIndex + 1] != "(" and t[charIndex - 2] != "(" and t[charIndex + 1] != "$" and t[charIndex + 1] != ")" and t[charIndex + 2] != ")" and t[charIndex + 3] != ")":
includeChar = False
if includeChar:
tempStr = tempStr + c
includeChar = True
charIndex = charIndex + 1
transitions[index] = tempStr
tempStr = ""
charIndex = 0
index = index + 1
index = 0
for t in transitions:
for c in t:
for d in numlist:
if c == d:
if charIndex + 1 >= len(t) and t[charIndex - 1] != "(":
includeChar = False
elif charIndex + 2 >= len(t) and t[charIndex - 1] != "(" and t[charIndex + 1] != "(" and t[charIndex + 1] != ")" and t[charIndex + 1:charIndex + 2] != "]":
includeChar = False
elif t[charIndex + 1:charIndex + 2] != "(" and t[charIndex + 2:charIndex + 3] != "(" and t[charIndex + 1:charIndex + 2] != ")" and t[charIndex + 1:charIndex + 2] != "]" and t[charIndex + 2:charIndex + 3] != ")" and t[charIndex - 1:charIndex] != "(" and t[charIndex + 2:charIndex + 3] != "$":
includeChar = False
if includeChar and t[charIndex:charIndex+2] != "78":
tempStr = tempStr + c
includeChar = True
charIndex = charIndex + 1
transitions[index] = tempStr
tempStr = ""
charIndex = 0
index = index + 1
rulestring = transitions[0] + transitions[1] + transitions[2] + transitions[3] + transitions[4] + transitions[5]
return rulestring
def generate_rulefile(rulestring,filename):
ruleStruct = ruleStructure
top = "@RULE " + filename
header = "\n\n@TABLE\nn_states:3\nneighborhood:Moore\nsymmetries:rotate4reflect\n\nvar a={0,1,2}\nvar ab={0,1,2}\nvar ac={0,1,2}\nvar ad={0,1,2}\nvar ae={0,1,2}\nvar af={0,1,2}\nvar ag={0,1,2}\nvar ah={0,1,2}\nvar ai={0,1,2}\n"
body = "\n"
tail = rulestring
currentNum = ""
currentConfig = ""
currentSubconfig = ""
currentVariant = None
currentPos = 0
currentBeginEnd = [0,1]
isInSubconfig = False
getFullNumList = False
getFullConfigList = False
charlist = ["c","e","k","a","i","n","y","q","j","r","t","w","z"]
for c in rulestring:
if c == "(" or c == "[":
isInSubconfig = True
if c == ")" or c == "]":
isInSubconfig = False
if isInSubconfig and c != "(":
currentPos = currentPos + 1
continue
#note: am planning on detecting subconfig on "(" and getting the
#numstring for it on ")"
if c == "A" or c == "B" or c == "T" or c == "S":
currentPos = currentPos + 1
continue
for n in [0,1,2,3,4,5,6,7,8]:
if c == str(n):
currentNum = n
if currentPos + 1 < len(rulestring):
if rulestring[currentPos+1] == str(n+1) or rulestring[currentPos+1] == "/":
getFullNumList = True
else:
getFullNumList = False
else:
getFullNumList = True
for k in charlist:
if c == k:
currentConfig = c
if currentPos + 1 < len(rulestring):
if rulestring[currentPos+1] != "(":
getFullConfigList = True
else:
getFullConfigList = False
else:
getFullConfigList = True
if c == "(":
currentSubconfig = rulestring[currentPos+1:rulestring.find(")",currentPos)]
if rulestring[rulestring.find(")",currentPos)+1:rulestring.find(")",currentPos)+2] == "[":
currentVariant = int(rulestring[rulestring.find("[",currentPos)+1:rulestring.find("[",currentPos)+2])
else:
currentVariant = None
if c == "/":
if rulestring[currentPos:currentPos+3] == "/BB":
currentBeginEnd = [0,2]
if rulestring[currentPos:currentPos+3] == "/TA":
currentBeginEnd = [1,2]
if rulestring[currentPos:currentPos+3] == "/TB":
currentBeginEnd = [2,1]
if rulestring[currentPos:currentPos+3] == "/SA":
currentBeginEnd = [1,1]
if rulestring[currentPos:currentPos+3] == "/SB":
currentBeginEnd = [2,2]
if getFullNumList:
for numbers in ruleStruct:
if numbers[0] == currentNum:
for configs in numbers:
if isinstance(configs,int):
continue
for subconfigs in configs:
if isinstance(subconfigs,str):
continue
body = body + str(currentBeginEnd[0]) + ","
for ch in subconfigs[3]:
body = body + ch + ","
body = body + str(currentBeginEnd[1]) + "\n"
if subconfigs[0] != subconfigs[1]:
body = body + str(currentBeginEnd[0]) + ","
for ch in subconfigs[4]:
body = body + ch + ","
body = body + str(currentBeginEnd[1]) + "\n"
if getFullConfigList:
for numbers in ruleStruct:
if numbers[0] == currentNum:
for configs in numbers:
if isinstance(configs,int):
continue
if configs[0] == currentConfig:
for subconfigs in configs:
if isinstance(subconfigs,str):
continue
body = body + str(currentBeginEnd[0]) + ","
for ch in subconfigs[3]:
body = body + ch + ","
body = body + str(currentBeginEnd[1]) + "\n"
if subconfigs[0] != subconfigs[1]:
body = body + str(currentBeginEnd[0]) + ","
for ch in subconfigs[4]:
body = body + ch + ","
body = body + str(currentBeginEnd[1]) + "\n"
if c == ")":
for numbers in ruleStruct:
if numbers[0] == currentNum:
for configs in numbers:
if isinstance(configs,int):
continue
if configs[0] == currentConfig:
for subconfigs in configs:
if isinstance(subconfigs,str):
continue
if currentSubconfig == subconfigs[0] + subconfigs[1] and currentVariant == subconfigs[2]:
body = body + str(currentBeginEnd[0]) + ","
for ch in subconfigs[3]:
body = body + ch + ","
body = body + str(currentBeginEnd[1]) + "\n"
elif currentSubconfig == subconfigs[1] + subconfigs[0] and currentVariant == subconfigs[2]:
body = body + str(currentBeginEnd[0]) + ","
for ch in subconfigs[4]:
body = body + ch + ","
body = body + str(currentBeginEnd[1]) + "\n"
getFullNumList = False
getFullConfigList = False
currentPos = currentPos + 1
body = body + "a,ab,ac,ad,ae,af,ag,ah,ai,0\n"
numlines = len(rulestring) // 999 + 1
filestring = top + header + body
for x in range(numlines):
filestring = filestring + "#" + tail[900*x:900*(x+1)] +"\n"
f = open(golly.getdir("rules") + filename + ".rule","w")
f.write(filestring)
f.close()
def get_rate_of_change_list(initList):
finalList = []
i = 0
while i < len(initList):
if i == 0:
finalList.append(0)
i = i + 1
continue
finalList.append(initList[i] - initList[i-1])
i = i + 1
return finalList
def get_median_list(initList):
finalList = []
y = []
for x in initList:
y = x
y.sort()
finalList.append(y[int(len(y)/2)])
return finalList
def c_check(halfBox,presentBox,presentDensity):
if halfBox[0] + checkWhen <= presentBox[0] or halfBox[1] + checkWhen <= presentBox[1]:
if presentDensity > checkDensity:
return True
return False
#returns a counterclockwise-rotated list; this is so that values in a sublist
#will be from the same generation, and that subsequent sublists will be from
#subsequent generations
def get_rotated_list(alist):
a = []
for x in zip(*alist[::1]):
a.append(list(x))
return a
#execution
#getting inputs from user
rulesToSearch = int(golly.getstring("How many rules to test:","100"))
if not os.path.isfile("rulegenconfig_3StateINT.txt"):
generate_config()
cfile = open("rulegenconfig_3StateINT.txt","r")
config = cfile.read()
cfile.close()
tempstring = ""
tempstring = config[config.find("search_number = ")+16:]
searchesPerRule = int(tempstring[:tempstring.find("\n")])
tempstring = config[config.find("search_length = ")+16:]
gensPerSearch = int(tempstring[:tempstring.find("\n")])
tempstring = config[config.find("stop_run_at_c = ")+16:]
breakAtC = bool(util.strtobool(tempstring[:tempstring.find("\n")]))
if breakAtC:
breakAtC = 1
else:
breakAtC = 0
if breakAtC == 1:
tempstring = config[config.find("c_check_when = ")+15:]
checkWhen = int(tempstring[:tempstring.find("\n")])
if checkWhen % 2 != 0:
checkWhen = checkWhen - 1
tempstring = config[config.find("c_density_check = ")+18:]
checkDensity = float(tempstring[:tempstring.find("\n")])
popLimitCheck = False
popLimit = 2 * 2 * gensPerSearch * gensPerSearch * gensPerSearch
else:
checkWhen = gensPerSearch + 2
checkDensity = 1
tempstring = config[config.find("population_stop_check = ")+24:]
popLimitCheck = bool(util.strtobool(tempstring[:tempstring.find("\n")]))
if popLimitCheck:
tempstring = config[config.find("stop_above_population = ")+24:]
popLimit = int(tempstring[:tempstring.find("\n")])
else:
popLimit = 2 * 2 * gensPerSearch * gensPerSearch * gensPerSearch
tempstring = config[config.find("start_stability_check_after_gen = ")+34:]
startStabilityCheck = int(tempstring[:tempstring.find("\n")])
tempstring = config[config.find("stability_change_gen = ")+23:]
stabilityChangeGen = int(tempstring[:tempstring.find("\n")])
tempstring = config[config.find("write_stable_data = ")+20:]
showStableData = bool(util.strtobool(tempstring[:tempstring.find("\n")]))
tempstring = config[config.find("write_exploding_data = ")+23:]
showExplodingData = bool(util.strtobool(tempstring[:tempstring.find("\n")]))
tempstring = config[config.find("write_chaotic_data = ")+21:]
showChaoticData = bool(util.strtobool(tempstring[:tempstring.find("\n")]))
tempstring = config[config.find("write_median_population = ")+26:]
showPopList = bool(util.strtobool(tempstring[:tempstring.find("\n")]))
tempstring = config[config.find("write_median_growth = ")+22:]
showGrowthList = bool(util.strtobool(tempstring[:tempstring.find("\n")]))
tempstring = config[config.find("write_median_acceleration = ")+28:]
showAccelerationList = bool(util.strtobool(tempstring[:tempstring.find("\n")]))
tempstring = config[config.find("write_median_density = ")+23:]
showDensityList = bool(util.strtobool(tempstring[:tempstring.find("\n")]))
tempstring = config[config.find("write_data_summary = ")+21:]
showSummary = bool(util.strtobool(tempstring[:tempstring.find("\n")]))
tempstring = config[config.find("visualize = ")+12:]
visualize = bool(util.strtobool(tempstring[:tempstring.find("\n")]))
for r in range(rulesToSearch):
#variables - reset for each rule
rule = generate_rulestring()
while rule[:6] == "BA/BB/":
rule = generate_rulestring()
currentSearch = 0
isStable = True
isExploding = False
maybeExploding = False
isChaotic = False
explodesAtC = False
exceedsPopulationLimit = False
populationList = []
populationChangeList = []
growthAccelerationList = []
densityList = []
finalBoxList = []
medianPopulationList = []
medianPopulationChangeList = []
medianGrowthAccelerationList = []
medianDensityList = []
averageFinalBox = [] #[[x,y]]
averageGrowthAcceleration = 0
medianFinalPopulation = 0
averageFinalDensity = 0
#execution
generate_rulefile(rule,"temp")
golly.new("h")
golly.setrule("temp")
golly.select([20,20,20,20])
#start of search loop
while currentSearch < searchesPerRule:
#variables - reset for each search
populationListTemp = []
densityListTemp = []
finalBox = []
populationChangeListTemp = []
growthAccelerationListTemp = []
currentGeneration = 0
#execution
golly.clear(1)
golly.randfill(50)
golly.show("Rule: " + str(r + 1) + " " * (30 - len(str(r + 1))) + "Search: " + str(currentSearch + 1))
if visualize:
golly.setpos("30","30")
golly.setmag(1)
golly.update()
#start of sim loop
while currentGeneration < gensPerSearch:
#special handling for gen 0
if currentGeneration == 0:
populationListTemp.append(int(golly.getpop()))
currentGeneration = currentGeneration + 1
golly.run(1)
if visualize:
golly.update()
currentPop = int(golly.getpop())
if len(golly.getrect()) != 0:
currentBox = [golly.getrect()[2],golly.getrect()[3]]
currentDensity = currentPop / (currentBox[0] * currentBox[1])
if currentBox[0] >= 22 or currentBox[1] >= 22:
if currentGeneration >= startStabilityCheck:
isStable = False
#<cCheck>
if currentGeneration == checkWhen / 2:
halBox = currentBox
if currentGeneration == checkWhen:
explodesAtC = c_check(halBox,currentBox,currentDensity)
if explodesAtC:
break
#</cCheck>
else:
currentBox = [0,0]
currentDensity = 0
if popLimitCheck and currentPop > popLimit:
exceedsPopulationLimit = True
break
populationListTemp.append(currentPop)
densityListTemp.append(currentDensity)
finalBox = currentBox
#end of sim loop
#<cCheck>
if explodesAtC or exceedsPopulationLimit:
break
#</cCheck>
populationChangeListTemp = get_rate_of_change_list(populationListTemp)
growthAccelerationListTemp = get_rate_of_change_list(populationChangeListTemp)
populationList.append(populationListTemp)
populationChangeList.append(populationChangeListTemp)
growthAccelerationList.append(growthAccelerationListTemp)
densityList.append(densityListTemp)
finalBoxList.append(finalBox)
currentSearch = currentSearch + 1
#end of search loop
if explodesAtC == False and exceedsPopulationLimit == False:
populationList = get_rotated_list(populationList)
populationChangeList = get_rotated_list(populationChangeList)
growthAccelerationList = get_rotated_list(growthAccelerationList)
densityList = get_rotated_list(densityList)
finalBoxList = get_rotated_list(finalBoxList)
medianPopulationList = get_median_list(populationList)
medianPopulationChangeList = get_median_list(populationChangeList)
medianGrowthAccelerationList = get_median_list(growthAccelerationList)
medianDensityList = get_median_list(densityList)
averageFinalBox.append(sum(finalBoxList[0])/len(finalBoxList[0]))
averageFinalBox.append(sum(finalBoxList[1])/len(finalBoxList[1]))
averageGrowthAcceleration = sum(medianGrowthAccelerationList)/len(medianGrowthAccelerationList)
medianFinalPopulation = medianPopulationList[len(medianPopulationList)-1]
averageFinalPopulation = sum(populationList[len(populationList)-1])/len(populationList[len(populationList)-1])
averageFinalDensity = sum(densityList[len(densityList)-1])/len(densityList[len(densityList)-1])
positive = 0
negative = 0
if medianPopulationChangeList[stabilityChangeGen] == 0 and medianPopulationChangeList[stabilityChangeGen+1] == 0 and medianPopulationChangeList[stabilityChangeGen+2] == 0 and medianPopulationChangeList[stabilityChangeGen+3] == 0 and medianPopulationChangeList[stabilityChangeGen+4] == 0:
isStable = True
for x in medianPopulationChangeList:
if x > 0:
positive = positive + 1
else:
negative = negative + 1
if positive > negative * 1.1 and isStable == False:
isExploding = True
elif positive > negative and isStable == False:
maybeExploding = True
if (medianFinalPopulation > gensPerSearch**1.6 or averageFinalPopulation > gensPerSearch**1.6) and golly.getrule()[:2] == "B0":
isExploding = True
if isExploding == False and isStable == False and maybeExploding == False:
isChaotic = True
logstring = rule + "\n"
if explodesAtC == False and exceedsPopulationLimit == False:
if showPopList and ((showStableData and isStable) or (showExplodingData and isExploding) or (showChaoticData and isChaotic)):
logstring = logstring + "Population: "
dex = 0
for x in medianPopulationList:
logstring = logstring + "[%d: %d]" % (dex,x) + " " * (6 - len(str(x)))
dex = dex + 1
if showGrowthList and ((showStableData and isStable) or (showExplodingData and isExploding) or (showChaoticData and isChaotic)):
logstring = logstring + "\nGrowth: "
dex = 0
for x in medianPopulationChangeList:
if dex == 0:
logstring = logstring + " " + " " * (6 - len(str(medianPopulationList[0])))
dex = dex + 1
continue
logstring = logstring + "[%d: %d]" % (dex,x) + " " * (6 - len(str(x)))
dex = dex + 1
if showAccelerationList and ((showStableData and isStable) or (showExplodingData and isExploding) or (showChaoticData and isChaotic)):
logstring = logstring + "\nAcceleration: "
dex = 0
for x in medianGrowthAccelerationList:
if dex == 0:
logstring = logstring + " " + " " * (6 - len(str(medianPopulationList[0])))
dex = dex + 1
continue
logstring = logstring + "[%d: %d]" % (dex,x) + " " * (6 - len(str(x)))
dex = dex + 1
if showDensityList and ((showStableData and isStable) or (showExplodingData and isExploding) or (showChaoticData and isChaotic)):
logstring = logstring + "\nDensity: "
dex = 0
for x in medianDensityList:
if dex == 0:
logstring = logstring + " " + " " * (6 - len(str(medianPopulationList[0])))
dex = dex + 1
continue
logstring = logstring + "[%d: %.3f]" % (dex,x) + " " * (6 - len(str(x)))
dex = dex + 1
if showSummary and ((showStableData and isStable) or (showExplodingData and isExploding) or (showChaoticData and isChaotic)):
logstring = logstring + "\n[Average Acceleration: %f]" % (averageGrowthAcceleration)
logstring = logstring + "[Median/Average Final Population: %d/%.2f]\n" % (medianFinalPopulation,averageFinalPopulation)
logstring = logstring + "[Average Final Bounding Box Size: %.2fx%.2f]" % (averageFinalBox[0],averageFinalBox[1])
logstring = logstring + "[Average Final Density: %f]\n" % (averageFinalDensity)
if isExploding:
logstring = logstring + "[Exploding]"
elif maybeExploding:
logstring = logstring + "[Possibly Exploding]"
elif isStable:
logstring = logstring + "[Stable]"
else:
logstring = logstring + "[Possibly Chaotic]"
else:
if explodesAtC:
logstring = logstring + "[Explodes at c]"
else:
logstring = logstring + "[Population Limit Exceeded]"
logstring = logstring + "\n\n"
while logstring.find("\n\n[") != -1:
logstring = logstring[:logstring.find("\n\n[")] + logstring[logstring.find("\n\n[")+1:]
if not os.path.isfile("rulelog_detailed_3StateINT.txt"):
g = open("rulelog_detailed_3StateINT.txt","w")
g.write("\n")
g.close()
g = open("rulelog_detailed_3StateINT.txt","a+")
g.write(logstring)
g.close()
os.remove(golly.getdir("rules") + "temp.rule")
golly.setrule("b3s23")
golly.new("h")
I also created a script that will turn a 3-State INT rulestring into a rulefile:
Code: Select all
import string
import os
import golly
rulestring = golly.getstring("Input rulestring:")
longfilename = ""
for c in rulestring:
if c != "/":
longfilename = longfilename + c
else:
longfilename = longfilename + "_"
filename = longfilename[:150]
ruleStruct = [[0,["",["","",None,"00000000","00000000"]]],[1,["c",["1c","0",None,"00000001","00000002"]],["e",["1e","0",None,"00000010","00000020"]]],[2,["c",["2c","0",None,"00000101","00000202"],["1c","1c",None,"00000102","00000201"]],["e",["2e","0",None,"00001010","00002020"],["1e","1e",None,"00001020","00002010"]],["k",["2k","0",None,"00001001","00002002"],["1e","1c",None,"00001002","00002001"]],["a",["2a","0",None,"00000011","00000022"],["1e","1c",None,"00000012","00000021"]],["i",["2i","0",None,"00100010","00200020"],["1e","1e",None,"00100020","00200010"]],["n",["2n","0",None,"00010001","00020002"],["1c","1c",None,"00010002","00020001"]]],[3,["c",["3c","0",None,"00010101","00020202"],["2n","1c",None,"00010201","00020102"],["2c","1c",None,"00010102","00020201"]],["e",["3e","0",None,"00101010","00202020"],["2i","1c",None,"00102010","00201020"],["2e","1e",None,"00101020","00202010"]],["k",["3k","0",None,"00101001","00202002"],["2e","1c",None,"00101002","00202001"],["2k","1e",None,"00102001","00201002"]],["a",["3a","0",None,"00001110","00002220"],["2e","1c",None,"00001210","00002120"],["2a","1e",None,"00001120","00002210"]],["i",["3i","0",None,"00000111","00000222"],["2a","1c",None,"00000112","00000221"],["2c","1e",None,"00000121","00000212"]],["n",["3n","0",None,"00001101","00002202"],["2a","1c",None,"00001102","00002201"],["2k","1c",None,"00001201","00002102"],["2c","1e",None,"00002101","00001202"]],["y",["3y","0",None,"00100101","00200202"],["2k","1c",None,"00100102","00200201"],["2c","1e",None,"00200101","00100202"]],["q",["3q","0",None,"00010011","00020022"],["2a","1c",None,"00020011","00010022"],["2k","1c",None,"00010012","00020021"],["2n","1e",None,"00010021","00020012"]],["j",["3j","0",None,"00001011","00002022"],["2e","1c",None,"00001012","00002021"],["2a","1e",None,"00002011","00001022"],["2k","1e",None,"00001021","00002012"]],["r",["3r","0",None,"00100011","00200022"],["2i","1c",None,"00100012","00200021"],["2a","1e",None,"00200011","00100022"],["2k","1e",None,"00100021","00200012"]]],[4,["c",["4c","0",None,"01010101","02020202"],["3c","1c",None,"01010102","02020201"],["2c","2c",None,"01010202","02020101"],["2n","2n",None,"01020102","02010201"]],["e",["4e","0",None,"10101010","20202020"],["3e","1e",None,"10101020","20202010"],["2e","2e",None,"10102020","20201010"],["2i","2i",None,"10201020","20102010"]],["k",["4k","0",None,"00101101","00202202"],["3j","1c",None,"00101102","00202201"],["3k","1c",None,"00101201","00202102"],["3y","1e",None,"00102101","00201202"],["3n","1e",None,"00201101","00102202"],["2e","2c",None,"00101202","00202101"],["2k","2k$",None,"00102102","00201201"],["2k","2a",None,"00102201","00201102"]],["a",["4a","0",None,"00001111","00002222"],["3j","1c",None,"00001211","00002122"],["3a","1c",None,"00001112","00002221"],["3n","1e",None,"00001121","00002212"],["3i","1e",None,"00002111","00001222"],["2e","2c",None,"00001212","00002121"],["2a","2a$",None,"00001122","00002211"],["2k","2a",None,"00001221","00002112"]],["i",["4i","0",None,"00110110","00220220"],["3r","1c",None,"00110210","00220120"],["3n","1e",None,"00110120","00220210"],["2i","2c",None,"00120210","00210120"],["2k","2k",None,"00120120","00210210"],["2a","2a",None,"00110220","00220110"]],["n",["4n","0",None,"00010111","00020222"],["3q","1c",None,"00010211","00020122"],["3n","1c",None,"00010112","00020221"],["3i","1c",None,"00020111","00010222"],["3c","1e",None,"00010121","00020212"],["2k","2c",None,"00010212","00020121"],["2n","2a",None,"00010221","00020112"],["2c","2a",None,"00010122","00020211"]],["y",["4y","0",None,"00110101","00220202"],["3q","1c",None,"00110201","00220102"],["3y","1c",None,"00120101","00210202"],["3n","1c",None,"00110102","00220201"],["3c","1e",None,"00210101","00120202"],["2a","2c",None,"00110202","00220101"],["2k","2c",None,"00120201","00210102"],["2k","2n",None,"00120102","00210201"]],["q",["4q","0",None,"00111001","00222002"],["3a","1c",None,"00111002","00222001"],["3k","1c",None,"00121001","00212002"],["3q","1e",None,"00112001","00221002"],["2a","2k",None,"00112002","00221001"],["2e","2n",None,"00121002","00212001"]],["j",["4j","0",None,"00101011","00202022"],["3e","1c",None,"00101012","00202021"],["3r","1e",None,"00102011","00201022"],["3j","1e",None,"00201011","00102022"],["3k","1e",None,"00101021","00202012"],["2k","2e",None,"00102021","00201012"],["2i","2k",None,"00102012","00201021"],["2e","2a",None,"00101022","00202011"]],["r",["4r","0",None,"00101110","00202220"],["3e","1c",None,"00101210","00202120"],["3r","1e",None,"00102110","00201220"],["3j","1e",None,"00101120","00202210"],["3a","1e",None,"00201110","00102220"],["2k","2e",None,"00102120","00201210"],["2i","2a",None,"00102210","00201120"],["2e","2a",None,"00101220","00202110"]],["t",["4t","0",None,"00100111","00200222"],["3r","1c",None,"00100112","00200221"],["3y","1e",None,"00100121","00200212"],["3i","1e",None,"00200111","00100222"],["2i","2c",None,"00100212","00200121"],["2k","2a",None,"00100122","00200211"]],["w",["4w","0",None,"00011011","00022022"],["3j","1c",None,"00011012","00022021"],["3q","1e",None,"00011021","00022012"],["2n","2e",None,"00012021","00021012"],["2k","2k",None,"00012012","00021021"],["2a","2a",None,"00011022","00022011"]],["z",["4z","0",None,"00110011","00220022"],["3r","1c",None,"00110012","00220021"],["3q","1e",None,"00110021","00220012"],["2k","2k",None,"00120021","00210012"],["2a","2a",None,"00110022","00220011"],["2i","2n",None,"00120012","00210021"]]],[5,["c",["5c","0",None,"10101011","20202022"],["4e","1c",None,"10101012","20202021"],["4r","1e",None,"10102011","20201022"],["4j","1e",None,"10101021","20202012"],["3j","2e",None,"10102021","20201012"],["3a","2e",None,"10202011","20101022"],["3k","2e",None,"20101021","10202012"],["3e","2k",None,"10102012","20201021"],["3e","2a",None,"10101022","20202011"],["3r","2i",None,"10201021","20102012"]],["e",["5e","0",None,"01010111","02020222"],["4y","1c",None,"01010112","02020221"],["4n","1c",None,"02010111","01020222"],["4c","1e",None,"01010121","02020212"],["3y","2c",None,"01010212","02020121"],["3n","2c",None,"02010112","01020221"],["3i","2c",None,"02020111","01010222"],["3c","2k",None,"02010121","01020212"],["3c","2a",None,"01010122","02020211"],["3q","2n",None,"01020112","02010221"]],["k",["5k","0",None,"01011011","02022022"],["4w","1c",None,"02011011","01022022"],["4k","1c",None,"01011012","02022021"],["4y","1e",None,"01011021","02022012"],["3j","2c",None,"02021011","01012022"],["3c","2e",None,"01012021","02021012"],["3q","2k",None,"02012011","01021022"],["3y","2k",None,"01012012","02021021"],["3n","2a",None,"01011022","02022011"],["3k","2n",None,"01021012","02012021"]],["a",["5a","0",None,"00011111","00022222"],["4w","1c",None,"00011211","00022122"],["4a","1c",None,"00011112","00022221"],["4n","1e",None,"00011121","00022212"],["3j","2c",None,"00011212","00022121"],["3c","2e",None,"00012121","00021212"],["3n","2k",None,"00012112","00021221"],["3q","2a",None,"00011221","00022112"],["3i","2a",None,"00011122","00022211"],["3a","2n",None,"00021112","00012221"]],["i",["5i","0",None,"00111110","00222220"],["4r","1c",None,"00111210","00222120"],["4i","1e",None,"00112110","00221220"],["4a","1e",None,"00111120","00222210"],["3e","2c",None,"00121210","00212120"],["3n","2e",None,"00112120","00221210"],["3j","2k",None,"00121120","00212210"],["3r","2a",None,"00112210","00221120"],["3a","2a",None,"00111220","00222110"],["3i","2i",None,"00211120","00122210"]],["n",["5n","0",None,"00101111","00202222"],["4r","1c",None,"00101112","00202221"],["4j","1c",None,"00101211","00202122"],["4t","1e",None,"00102111","00201222"],["4a","1e",None,"00201111","00102222"],["4k","1e",None,"00101121","00202212"],["3e","2c",None,"00101212","00202121"],["3y","2e",None,"00102121","00201212"],["3i","2e",None,"00202111","00101222"],["3r","2k",None,"00102112","00201221"],["3j","2k",None,"00201211","00102122"],["3a","2k",None,"00201112","00102221"],["3r","2a",None,"00102211","00201122"],["3j","2a",None,"00101122","00202211"],["3k","2a",None,"00101221","00202112"],["3n","2i",None,"00201121","00102212"]],["y",["5y","0",None,"01101011","02202022"],["4j","1c",None,"01101012","02202021"],["4i","1e",None,"01102011","02201022"],["4k","1e",None,"01101021","02202012"],["3e","2c",None,"02101012","01202021"],["3n","2e",None,"01102021","02201012"],["3r","2k",None,"01102012","02201021"],["3k","2k",None,"01201012","02102021"],["3j","2a",None,"01101022","02202011"],["3y","2i",None,"01201021","02102012"]],["q",["5q","0",None,"00111011","00222022"],["4r","1c",None,"00111012","00222021"],["4j","1c",None,"00121011","00212022"],["4z","1e",None,"00112011","00221022"],["4w","1e",None,"00211011","00122022"],["4q","1e",None,"00111021","00222012"],["3q","2e",1,"00112021","00221012"],["3q","2e",2,"00212011","00121022"],["3r","2k",None,"00112012","00221021"],["3j","2k",None,"00211012","00122021"],["3k","2k",None,"00121021","00212012"],["3r","2a",None,"00122011","00211022"],["3j","2a",None,"00221011","00112022"],["3a","2a",None,"00111022","00222011"],["3q","2i",None,"00211021","00122012"],["3e","2n",None,"00121012","00212021"]],["j",["5j","0",None,"00111101","00222202"],["4q","1c",None,"00111201","00222102"],["4a","1c",None,"00111102","00222201"],["4k","1c",None,"00121101","00212202"],["4y","1e",None,"00112101","00221202"],["4n","1e",None,"00211101","00122202"],["3a","2c",None,"00111202","00222101"],["3k","2c",None,"00121201","00212102"],["3c","2e",None,"00212101","00121202"],["3q","2k",None,"00211201","00122102"],["3n","2k",None,"00112102","00221201"],["3i","2k",None,"00211102","00122201"],["3q","2a",None,"00112201","00221102"],["3y","2a",None,"00122101","00211202"],["3n","2a",None,"00221101","00112202"],["3j","2n",None,"00121102","00212201"]],["r",["5r","0",None,"00110111","00220222"],["4z","1c",None,"00110211","00220122"],["4t","1c",None,"00120111","00210222"],["4i","1c",None,"00110112","00220221"],["4y","1e",None,"00110121","00220212"],["4n","1e",None,"00210111","00120222"],["3r","2c",1,"00110212","00220121"],["3r","2c",2,"00120211","00210122"],["3q","2k",None,"00210211","00120122"],["3y","2k",None,"00120121","00210212"],["3n","2k",None,"00210112","00120221"],["3q","2a",None,"00110221","00220112"],["3n","2a",None,"00110122","00220211"],["3i","2a",None,"00220111","00110222"],["3c","2i",None,"00210121","00120212"],["3r","2n",None,"00120112","00210221"]]],[6,["c",["6c","0",None,"10101111","20202222"],["5c","1c",None,"10101112","20202221"],["5y","1e",None,"10101121","20202212"],["5n","1e",None,"10102111","20201222"],["5i","1e",None,"10201111","20102222"],["4e","2c",None,"10101212","20202121"],["4a","2e",None,"20201111","10102222"],["4k","2e",None,"10102121","20201212"],["4r","2k",None,"10201112","20102221"],["4j","2k",None,"10102112","20201221"],["4r","2a",None,"10102211","20201122"],["4j","2a",None,"10101122","20202211"],["4t","2i",None,"20102111","10201222"],["4i","2i",None,"10201121","20102212"],["3j","3a",None,"10102221","20201112"],["3e","3i",None,"10101222","20202111"],["3e","3n",None,"10102212","20201121"],["3e","3y",None,"10201212","20102121"],["3k","3j",None,"10102122","20201211"],["3r","3r$",None,"10201122","20102211"]],["e",["6e","0",None,"01011111","02022222"],["5j","1c",None,"01011112","02022221"],["5a","1c",None,"02011111","01022222"],["5k","1c",None,"01011211","02022122"],["5e","1e",None,"01011121","02022212"],["4a","2c",None,"02021111","01012222"],["4k","2c",None,"01011212","02022121"],["4c","2e",None,"01012121","02021212"],["4y","2k",None,"01012112","02021221"],["4n","2k",None,"02012111","01021222"],["4y","2a",None,"01011221","02022112"],["4n","2a",None,"01011122","02022211"],["4w","2n",None,"02011211","01022122"],["4q","2n",None,"01021112","02012221"],["3k","3c",None,"01021212","02012121"],["3c","3a",None,"01012221","02021112"],["3n","3i",None,"01011222","02022111"],["3y","3n",None,"01012212","02021121"],["3q","3q$",None,"01021122","02012211"],["3c","3j",None,"01012122","02021211"]],["k",["6k","0",None,"01101111","02202222"],["5q","1c",None,"01101112","02202221"],["5y","1c",None,"01101211","02202122"],["5n","1c",None,"02101111","01202222"],["5r","1e",None,"01102111","02201222"],["5j","1e",None,"01201111","02102222"],["5k","1e",None,"01101121","02202212"],["4r","2c",None,"02101112","01202221"],["4j","2c",None,"01101212","02202121"],["4y","2e",None,"01102121","02201212"],["4n","2e",None,"01202111","02101222"],["4z","2k",None,"01102112","02201221"],["4t","2k",None,"02102111","01201222"],["4q","2k",None,"01201112","02102221"],["4k","2k",1,"01201211","02102122"],["4k","2k",2,"02101121","01202212"],["4w","2a",None,"01101122","02202211"],["4i","2a",None,"01102211","02201122"],["4a","2a",None,"02201111","01102222"],["4k","2a",None,"01101221","02202112"],["4y","2i",None,"01201121","02102212"],["4j","2n",None,"02101211","01202122"],["3c","3e",None,"01202121","02101212"],["3q","3k",None,"01202112","02101221"],["3n","3a",None,"01102221","02201112"],["3j","3i",None,"01101222","02202111"],["3r","3n",None,"01102212","02201121"],["3k","3y",None,"01201212","02102121"],["3r","3q",None,"02102211","01201122"],["3q","3j",None,"01102122","02201211"],["3n","3j",None,"01202211","02101122"],["3y","3r",None,"01201221","02102112"]],["a",["6a","0",None,"00111111","00222222"],["5q","1c",None,"00111211","00222122"],["5n","1c",None,"00121111","00212222"],["5i","1c",None,"00111112","00222221"],["5r","1e",None,"00112111","00221222"],["5j","1e",None,"00111121","00222212"],["5a","1e",None,"00211111","00122222"],["4r","2c",None,"00111212","00222121"],["4j","2c",None,"00121211","00212122"],["4y","2e",None,"00112121","00221212"],["4n","2e",None,"00212111","00121222"],["4w","2k",None,"00211211","00122122"],["4i","2k",None,"00112112","00221221"],["4a","2k",None,"00211112","00122221"],["4k","2k",None,"00121121","00212212"],["4z","2a",None,"00112211","00221122"],["4t","2a",None,"00122111","00211222"],["4q","2a",None,"00111221","00222112"],["4a","2a",1,"00111122","00222211"],["4a","2a",2,"00221111","00112222"],["4n","2i",None,"00211121","00122212"],["4r","2n",None,"00121112","00212221"],["3e","3c",None,"00121212","00212121"],["3q","3a",None,"00112221","00221112"],["3r","3i",None,"00122211","00211122"],["3a","3i",None,"00111222","00222111"],["3r","3n",None,"00112212","00221121"],["3k","3n",None,"00121221","00212112"],["3r","3q",None,"00122112","00211221"],["3j","3q",None,"00121122","00212211"],["3y","3j",None,"00122121","00211212"],["3n","3j",None,"00112122","00221211"]],["i",["6i","0",None,"01110111","02220222"],["5r","1c",None,"01110112","02220221"],["5e","1e",None,"01110121","02220212"],["4t","2c",None,"01110212","02220121"],["4i","2c",None,"01120211","02210122"],["4y","2k",None,"01120121","02210212"],["4n","2a",None,"01110122","02220211"],["4c","2i",None,"01210121","02120212"],["4z","2n",None,"01120112","02210221"],["3r","3c",None,"01120212","02210121"],["3i","3i",None,"01110222","02220111"],["3n","3n",None,"01120221","02210112"],["3y","3y",None,"01210212","02120121"],["3q","3q",None,"01120122","02210211"]],["n",["6n","0",None,"10111011","20222022"],["5c","1c",None,"10111012","20222021"],["5q","1e",None,"10111021","20222012"],["4w","2e",None,"10112021","20221012"],["4q","2e",None,"10212011","20121022"],["4j","2k",None,"10112012","20221021"],["4r","2a",None,"10111022","20222011"],["4z","2i",None,"10211021","20122012"],["4e","2n",None,"10121012","20212021"],["3q","3q",None,"10212012","20121021"],["3a","3a",None,"10222011","20111022"],["3e","3q",None,"10121022","20212011"],["3j","3j",None,"10112022","20221011"],["3r","3r",None,"10211022","20122011"]]],[7,["c",["7c","0",None,"10111111","20222222"],["6n","1c",None,"10111211","20222122"],["6c","1c",None,"10111112","20222221"],["6a","1e",None,"10211111","20122222"],["6k","1e",None,"10111121","20222212"],["5c","2c",None,"10111212","20222121"],["5j","2e",None,"10212111","20121222"],["5a","2e",None,"20211111","10122222"],["5k","2e",None,"10112121","20221212"],["5q","2k",None,"10211211","20122122"],["5y","2k",None,"10112112","20221221"],["5n","2k",None,"10211112","20122221"],["5q","2a",None,"10111221","20222112"],["5n","2a",None,"10111122","20222211"],["5i","2a",None,"10221111","20112222"],["5r","2i",None,"10211121","20122212"],["5c","2n",None,"10121112","20212221"],["4e","3c",None,"10121212","20212121"],["4y","3e",None,"10212121","20121212"],["4n","3e",None,"20212111","10121222"],["4w","3k",None,"20211211","10122122"],["4k","3k",None,"10212112","20121221"],["4w","3a",None,"10112221","20221112"],["4a","3a",None,"10222111","20111222"],["4r","3i",None,"10111222","20222111"],["4r","3n",None,"10221211","20112122"],["4j","3n",None,"10112212","20221121"],["4j","3y",None,"10211212","20122121"],["4r","3q",None,"20121112","10212221"],["4j","3q",None,"10121122","20212211"],["4q","3j",None,"10212211","20121122"],["4a","3j",None,"20221111","10112222"],["4k","3j",None,"10112122","20221211"],["4z","3r",None,"10211221","20122112"],["4t","3r",None,"10211122","20122211"],["4i","3r",None,"10221121","20112212"]],["e",["7e","0",None,"01111111","02222222"],["6a","1c",None,"01111112","02222221"],["6k","1c",None,"01111211","02222122"],["6i","1e",None,"01112111","02221222"],["6e","1e",None,"01111121","02222212"],["5y","2c",None,"01121211","02212122"],["5n","2c",None,"01111212","02222121"],["5i","2c",None,"02111112","01222221"],["5e","2e",None,"01112121","02221212"],["5r","2k",None,"01112112","02221221"],["5j","2k",None,"01211112","02122221"],["5k","2k",None,"01121121","02212212"],["5r","2a",None,"01112211","02221122"],["5j","2a",None,"01111221","02222112"],["5a","2a",None,"01111122","02222211"],["5e","2i",None,"01211121","02122212"],["5q","2n",None,"01121112","02212221"],["4r","3c",None,"02121112","01212221"],["4j","3c",None,"01121212","02212121"],["4c","3e",None,"01212121","02121212"],["4y","3k",None,"01212112","02121221"],["4n","3a",None,"01112221","02221112"],["4i","3i",None,"01122211","02211122"],["4a","3i",None,"01111222","02222111"],["4t","3n",None,"01112212","02221121"],["4a","3n",None,"02211112","01122221"],["4k","3n",None,"01121221","02212112"],["4i","3y",None,"02112112","01221221"],["4k","3y",None,"01211212","02122121"],["4z","3q",None,"01122112","02211221"],["4w","3q",None,"01121122","02212211"],["4q","3q",None,"01221112","02112221"],["4y","3j",None,"01122121","02211212"],["4n","3j",None,"01112122","02221211"],["4y","3r",None,"01211221","02122112"],["4n","3r",None,"02211121","01122212"]]],[8,["",["8","0",None,"11111111","22222222"],["7c","1c",None,"11111112","22222221"],["7e","1e",None,"11111121","22222212"],["6c","2c",None,"11111212","22222121"],["6e","2e",None,"11112121","22221212"],["6k","2k",None,"11112112","22221221"],["6a","2a",None,"11111122","22222211"],["6i","2i",None,"11211121","22122212"],["6n","2n",None,"11121112","22212221"],["5c","3c",None,"11121212","22212121"],["5e","3e",None,"11212121","22121212"],["5k","3k",None,"11212112","22121221"],["5a","3a",None,"11112221","22221112"],["5i","3i",None,"11111222","22222111"],["5n","3n",None,"11112212","22221121"],["5y","3y",None,"11211212","22122121"],["5q","3q",None,"11121122","22212211"],["5j","3j",None,"11112122","22221211"],["5r","3r",None,"11211122","22122211"],["4e","4c",None,"12121212","21212121"],["4k","4k",None,"11212212","22121121"],["4a","4a",None,"11112222","22221111"],["4r","4n",None,"11121222","22212111"],["4y","4j",None,"11212122","22121211"],["4i","4t",None,"11211222","22122111"],["4q","4w",None,"11122122","22211211"],["4z","4z",None,"11221122","22112211"]]]]
top = "@RULE " + filename
header = "\n\n@TABLE\nn_states:3\nneighborhood:Moore\nsymmetries:rotate4reflect\n\nvar a={0,1,2}\nvar ab={0,1,2}\nvar ac={0,1,2}\nvar ad={0,1,2}\nvar ae={0,1,2}\nvar af={0,1,2}\nvar ag={0,1,2}\nvar ah={0,1,2}\nvar ai={0,1,2}\n"
body = "\n"
tail = rulestring
currentNum = ""
currentConfig = ""
currentSubconfig = ""
currentPos = 0
currentBeginEnd = [0,1]
isInSubconfig = False
getFullNumList = False
getFullConfigList = False
charlist = ["c","e","k","a","i","n","y","q","j","r","t","w","z"]
for c in rulestring:
if c == "(" or c == "[":
isInSubconfig = True
if c == ")" or c == "]":
isInSubconfig = False
if isInSubconfig and c != "(":
currentPos = currentPos + 1
continue
#note: am planning on detecting subconfig on "(" and getting the
#numstring for it on ")"
if c == "A" or c == "B" or c == "T" or c == "S":
currentPos = currentPos + 1
continue
for n in [0,1,2,3,4,5,6,7,8]:
if c == str(n):
currentNum = n
if currentPos + 1 < len(rulestring):
if rulestring[currentPos+1] == str(n+1) or rulestring[currentPos+1] == "/":
getFullNumList = True
else:
getFullNumList = False
else:
getFullNumList = True
for k in charlist:
if c == k:
currentConfig = c
if currentPos + 1 < len(rulestring):
if rulestring[currentPos+1] != "(":
getFullConfigList = True
else:
getFullConfigList = False
else:
getFullConfigList = True
if c == "(":
currentSubconfig = rulestring[currentPos+1:rulestring.find(")",currentPos)]
if rulestring[rulestring.find(")",currentPos)+1:rulestring.find(")",currentPos)+2] == "[":
currentVariant = int(rulestring[rulestring.find("[",currentPos)+1:rulestring.find("[",currentPos)+2])
else:
currentVariant = None
if c == "/":
if rulestring[currentPos:currentPos+3] == "/BB":
currentBeginEnd = [0,2]
if rulestring[currentPos:currentPos+3] == "/TA":
currentBeginEnd = [1,2]
if rulestring[currentPos:currentPos+3] == "/TB":
currentBeginEnd = [2,1]
if rulestring[currentPos:currentPos+3] == "/SA":
currentBeginEnd = [1,1]
if rulestring[currentPos:currentPos+3] == "/SB":
currentBeginEnd = [2,2]
if getFullNumList:
for numbers in ruleStruct:
if numbers[0] == currentNum:
for configs in numbers:
if isinstance(configs,int):
continue
for subconfigs in configs:
if isinstance(subconfigs,str):
continue
body = body + str(currentBeginEnd[0]) + ","
for ch in subconfigs[3]:
body = body + ch + ","
body = body + str(currentBeginEnd[1]) + "\n"
if subconfigs[0] != subconfigs[1]:
body = body + str(currentBeginEnd[0]) + ","
for ch in subconfigs[4]:
body = body + ch + ","
body = body + str(currentBeginEnd[1]) + "\n"
if getFullConfigList:
for numbers in ruleStruct:
if numbers[0] == currentNum:
for configs in numbers:
if isinstance(configs,int):
continue
if configs[0] == currentConfig:
for subconfigs in configs:
if isinstance(subconfigs,str):
continue
body = body + str(currentBeginEnd[0]) + ","
for ch in subconfigs[3]:
body = body + ch + ","
body = body + str(currentBeginEnd[1]) + "\n"
if subconfigs[0] != subconfigs[1]:
body = body + str(currentBeginEnd[0]) + ","
for ch in subconfigs[4]:
body = body + ch + ","
body = body + str(currentBeginEnd[1]) + "\n"
if c == ")":
for numbers in ruleStruct:
if numbers[0] == currentNum:
for configs in numbers:
if isinstance(configs,int):
continue
if configs[0] == currentConfig:
for subconfigs in configs:
if isinstance(subconfigs,str):
continue
if currentSubconfig == subconfigs[0] + subconfigs[1]and currentVariant == subconfigs[2]:
body = body + str(currentBeginEnd[0]) + ","
for ch in subconfigs[3]:
body = body + ch + ","
body = body + str(currentBeginEnd[1]) + "\n"
elif currentSubconfig == subconfigs[1] + subconfigs[0]and currentVariant == subconfigs[2]:
body = body + str(currentBeginEnd[0]) + ","
for ch in subconfigs[4]:
body = body + ch + ","
body = body + str(currentBeginEnd[1]) + "\n"
getFullNumList = False
getFullConfigList = False
currentPos = currentPos + 1
body = body + "a,ab,ac,ad,ae,af,ag,ah,ai,0\n"
numlines = len(rulestring) // 999 + 1
filestring = top + header + body
for x in range(numlines):
filestring = filestring + "#" + tail[900*x:900*(x+1)] +"\n"
f = open(golly.getdir("rules") + filename + ".rule","w")
f.write(filestring)
f.close()
golly.setrule(filename)