Commit 093e8e8e authored by Adam P. Goucher's avatar Adam P. Goucher
Browse files

Convert isotropic_metafier to single Python script

parent cc50489a
......@@ -10,6 +10,7 @@ except ImportError:
os.system("bash update-lifelib.sh")
from lifelib.genera.isotropic import str2tab
import lifelib
def rule2tuples(rulestring):
......@@ -66,7 +67,7 @@ def tuples2vn(tuples, filename):
def tuples2tape(tuples):
print([0] + ([90]*41))
tape = [0] + ([90]*41)
# Amount of time to wait between finishing the 42-glider salute and
# beginning the first entry of the transition table:
......@@ -93,22 +94,65 @@ def tuples2tape(tuples):
for _ in range(j - 1):
l += [90]
debt -= 90
print(l)
tape += l
debt += 1024
print([debt + 10000])
tape += [debt + 10000]
return tape
if __name__ == '__main__':
def main():
from sys import argv
if (len(argv) < 2):
raise TypeError("Usage: python mktable.py RULESTRING [output.rule]")
if (len(argv) != 3):
raise TypeError("Usage: python isotropic_metafier.py infile.rle outfile.mc [outfile.rule]")
sess = lifelib.load_rules('b3s23')
lt = sess.lifetree()
pattern_to_metafy = lt.load(argv[1])
original_rule = pattern_to_metafy.getrule()
# Cast to b3s23:
pattern_to_metafy = lt.pattern("", "b3s23") + pattern_to_metafy
rtuples = rule2tuples(original_rule)
tape = tuples2tape(rtuples)
if (len(argv) >= 4):
tuples2vn(rtuples, argv[3])
empty_cell = lt.load("metacell/emptycell.mc")
cell_without_glider = empty_cell & empty_cell[8]
glider = empty_cell - cell_without_glider
cell_with_tape = cell_without_glider + glider.stream(tape)
rtuples = rule2tuples(argv[1])
tuples2tape(rtuples)
# Run in HashLife:
gensleft = 430531840
while (gensleft > 16777216):
cell_with_tape = cell_with_tape[16777216]
gensleft -= 16777216
print('%d generations remaining...' % gensleft)
cell_with_tape = cell_with_tape[gensleft]
print('Loading patterns...')
default_cell = lt.load("metacell/tableonly_default.mc")
default_cell_full = lt.load("metacell/complete_default.mc")
print('Applying patch...')
onecell = (cell_with_tape ^ default_cell) ^ default_cell_full
onecell = onecell.centre()
metafied_pattern = pattern_to_metafy * onecell
metafied_pattern.write_file(argv[2])
print('...saved output in %s' % argv[2])
if __name__ == '__main__':
if (len(argv) >= 3):
tuples2vn(rtuples, argv[2])
main()
#!/bin/bash
if [ "$#" -ne 2 ]; then
echo "Usage: ./isotropic_metafier.sh INPUT_PATTERN OUTPUT_PATTERN"
echo "The input file can be either .rle or .mc"
echo "The output file is guaranteed to be .mc"
exit 1
fi
INPUT_FILE=$(readlink -f "$1")
OUTPUT_FILE=$(readlink -f "$2")
cd "$( dirname "${BASH_SOURCE[0]}" )"
rm -r temp | true
mkdir -p temp
grep '^x' "$INPUT_FILE" > temp/ruledata.txt
grep '^#R' "$INPUT_FILE" >> temp/ruledata.txt
RULESTRING=$( head -n 1 temp/ruledata.txt | tr ' ' '\n' | tr '=' '\n' | tail -n 1 )
# Abort if anything goes wrong.
set -e
echo "rule : '$RULESTRING'"
python mktable.py "$RULESTRING" > temp/ruletable.txt
echo "Table successfully created."
if [ -f "lifelib/dd0e0p" ]; then
echo "dd0e0p exists"
else
bash update-lifelib.sh
cd lifelib
echo "Compiling dd0e0p..."
g++ -O3 -march=native -std=c++11 -Wall -Wextra dd0e0p.cpp -o dd0e0p
cd -
fi
echo "Imaging ruletable into empty metacell..."
lifelib/dd0e0p if=temp/ruletable.txt tf=metacell/emptycell.mc of=temp/tableonly_new.mc absolute=430531840 bs=16777216 final
echo "...completed."
if [ -f "metacell/xorkron" ]; then
echo "xorkron exists"
else
echo "Compiling xorkron..."
cd metacell
g++ -O3 -march=native -std=c++11 -Wall -Wextra xorkron.cpp -o xorkron
cd -
fi
echo "Constructing metapattern..."
metacell/xorkron "temp/tableonly_new.mc" "metacell/tableonly_default.mc" "metacell/complete_default.mc" "$INPUT_FILE" "$OUTPUT_FILE"
rm -r temp
echo "...constructed."
Subproject commit e39d9e96b68da2d988ed2187f711755c077878fd
Subproject commit 68523a2c3839daace2db840d2f45b0212da276a4
#include "../lifelib/pattern2.h"
int main(int argc, char* argv[]) {
apg::lifetree<uint32_t, 4> lt(1500);
apg::pattern part1(&lt, std::string(argv[1]));
apg::pattern part2(&lt, std::string(argv[2]));
apg::pattern part3(&lt, std::string(argv[3]));
apg::pattern patch = part1 ^ part2;
apg::pattern onecell = patch ^ part3;
apg::pattern nocell(&lt, "", "b3s23");
onecell = onecell.centre();
apg::pattern origpattern(&lt, std::string(argv[4]));
apg::pattern metapattern = origpattern.tensor(onecell, nocell);
std::ofstream out(argv[5]);
metapattern.write_macrocell(out);
return 0;
}
......@@ -4,8 +4,7 @@ then
if [ -d "lifelib/avxlife" ]
then
printf "Ensuring lifelib is up-to-date...\n"
# rm -rf "lifelib/avxlife/lifelogic" | true
# python lifelib/rule3asm.py "b3s23" > /dev/null
printf "import lifelib\nlifelib.reset_tree()\n" | python
else
printf "\033[33;1mDownloading lifelib...\033[0m\n"
fi
......
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