Created
August 23, 2010 16:19
-
-
Save rraval/545798 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
width = 40 | |
height = 30 | |
alive = '#' | |
dead = '-' | |
for i in range(height): | |
for j in range(width): | |
print "#ifndef CELL_%02d_%02d" % (i, j) | |
print "#define CELL_%02d_%02d 0" % (i, j) | |
print "#endif" | |
print "#undef GRID_%02d_%02d" % (i, j) | |
for i in range(height): | |
for j in range(width): | |
neighbours = filter(lambda pair: pair[0] >= 0 and pair[0] < height | |
and pair[1] >= 0 and pair[1] < width, | |
[(i - 1, j - 1), (i - 1, j), (i - 1, j + 1), | |
(i, j - 1), (i, j + 1), | |
(i + 1, j - 1), (i + 1, j), (i + 1, j + 1)]) | |
cell = "CELL_%02d_%02d" % (i, j) | |
grid = "GRID_%02d_%02d" % (i, j) | |
print "#define COND %s" % '+'.join(map(lambda pair: "CELL_%02d_%02d" % pair, neighbours)) | |
print "#if (%s && (COND >= 2) && (COND <= 3)) || (!%s && (COND == 3))" % (cell, cell) | |
print "#define %s %s" % (grid, alive) | |
print "#define NEXT_%02d_%02d 1" % (i, j) | |
print "#else" | |
print "#define %s %s" % (grid, dead) | |
print "#define NEXT_%02d_%02d 0" % (i, j) | |
print "#endif" | |
print "#undef COND" | |
for i in range(height): | |
for j in range(width): | |
print "#undef CELL_%02d_%02d" % (i, j) | |
print "#if NEXT_%02d_%02d" % (i, j) | |
print "#define CELL_%02d_%02d 1" % (i, j) | |
print "#endif" | |
print "#undef NEXT_%02d_%02d" % (i, j) | |
for i in range(height): | |
print ' '.join(map(lambda j: "GRID_%02d_%02d" % (i, j), range(width))) | |
print "#include __FILE__" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define CELL_00_01 1 | |
#define CELL_01_02 1 | |
#define CELL_02_00 1 | |
#define CELL_02_01 1 | |
#define CELL_02_02 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define CELL_05_01 1 | |
#define CELL_05_02 1 | |
#define CELL_06_01 1 | |
#define CELL_06_02 1 | |
#define CELL_05_11 1 | |
#define CELL_06_11 1 | |
#define CELL_07_11 1 | |
#define CELL_04_12 1 | |
#define CELL_08_12 1 | |
#define CELL_03_13 1 | |
#define CELL_03_14 1 | |
#define CELL_09_13 1 | |
#define CELL_09_14 1 | |
#define CELL_06_15 1 | |
#define CELL_04_16 1 | |
#define CELL_08_16 1 | |
#define CELL_05_17 1 | |
#define CELL_06_17 1 | |
#define CELL_07_17 1 | |
#define CELL_06_18 1 | |
#define CELL_03_21 1 | |
#define CELL_04_21 1 | |
#define CELL_05_21 1 | |
#define CELL_03_22 1 | |
#define CELL_04_22 1 | |
#define CELL_05_22 1 | |
#define CELL_02_23 1 | |
#define CELL_06_23 1 | |
#define CELL_01_25 1 | |
#define CELL_02_25 1 | |
#define CELL_06_25 1 | |
#define CELL_07_25 1 | |
#define CELL_03_35 1 | |
#define CELL_03_36 1 | |
#define CELL_04_35 1 | |
#define CELL_04_36 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment