Skip to content

Instantly share code, notes, and snippets.

@MarkJeronimus
Last active June 8, 2020 20:42
Show Gist options
  • Select an option

  • Save MarkJeronimus/2aeea4c9299b0ff2d7e6e9e62558e0a3 to your computer and use it in GitHub Desktop.

Select an option

Save MarkJeronimus/2aeea4c9299b0ff2d7e6e9e62558e0a3 to your computer and use it in GitHub Desktop.
set-non-totalistic-vonNeumann-rule.py
import golly as g
from glife import *
napkinLetters=[' ', 'c', 'e', 'k', 'a', 'i', 'n', 'y', 'q', 'j', 'r', 't', 'w', 'z']
mooreParts = ["0 ", \
"1e", \
"2e", \
"2i", \
"3e", \
"4e"]
vonNeumanParts = ["0 ", \
"1e", \
"2e", \
"2i", \
"3 ", \
"4 "]
vonNeumanMapping = [["0 ", "1c", "2c", "2n", "3c", "4c"], \
["1 ", "1e", "2k", "2a", "3i", "3n", "3y", "3q", "4n", "4y", "5e"], \
["2e", "3k", "3a", "3j", "4k", "4a", "4q", "4w", "5k", "5a", "5j", "6e"], \
["2i", "3r", "4i", "4t", "4z", "5r", "6i"], \
["3 ", "3e", "4j", "4r", "5i", "5n", "5y", "5q", "6k", "6a", "7e"], \
["4 ", "4e", "5c", "6c", "6n", "7c", "8 "]]
def addAllLetters(napkinDigit):
for i in range(0, 14):
napkinDigit[i] = True;
def toNapkin(rule):
napkin = [[[False for k in xrange(14)] for j in xrange(9)] for i in xrange(2)]
side = 0
digit = 0
lastWasDigit = False
positive = True
for c in rule:
if c == 'B':
if lastWasDigit:
addAllLetters(napkin[side][digit])
side = 0
lastWasDigit = False
elif c == 'S':
if lastWasDigit:
addAllLetters(napkin[side][digit])
side = 1
lastWasDigit = False
elif c == '/':
pass
elif c.isdigit():
if lastWasDigit:
addAllLetters(napkin[side][digit])
digit = int(c)
lastWasDigit = True
positive = True
elif c == '-':
if not lastWasDigit:
g.exit("Minus not following a digit: " + rule)
positive = False
addAllLetters(napkin[side][digit])
elif c.isalpha():
lastWasDigit = False
napkin[side][digit][napkinLetters.index(c)] = positive
else:
g.exit("Unrecognized character in rule: " + rule)
if lastWasDigit:
addAllLetters(napkin[side][digit])
return napkin
def vonNumanize(napkin):
for side in range(0, 2):
for i in range(0, 6):
digit = int(mooreParts[i][0])
letter = napkinLetters.index(mooreParts[i][1])
present = napkin[side][digit][letter]
for code in vonNeumanMapping[i]:
digit = int(code[0])
letter = napkinLetters.index(code[1])
napkin[side][digit][letter] = present
return napkin
def mooreize(napkin):
for side in range(0, 2):
for i in range(0, 6):
digit = int(vonNeumanParts[i][0])
letter = napkinLetters.index(vonNeumanParts[i][1])
present = napkin[side][digit][letter]
for code in vonNeumanMapping[i]:
digit = int(code[0])
letter = napkinLetters.index(code[1])
napkin[side][digit][letter] = present
return napkin
def toVonNeumanRule(napkin):
rule = "B"
for i in range(0, 6):
digit = int(mooreParts[i][0])
letter = napkinLetters.index(mooreParts[i][1])
if napkin[0][digit][letter]:
rule += mooreParts[i]
rule += "/S"
for i in range(0, 6):
digit = int(mooreParts[i][0])
letter = napkinLetters.index(mooreParts[i][1])
if napkin[1][digit][letter]:
rule += mooreParts[i]
return rule
def toMooreRule(napkin):
rule = "B"
for i in range(0, 6):
digit = int(vonNeumanParts[i][0])
letter = napkinLetters.index(vonNeumanParts[i][1])
if napkin[0][digit][letter]:
rule += "".join(vonNeumanMapping[i])
rule += "/S"
for i in range(0, 6):
digit = int(vonNeumanParts[i][0])
letter = napkinLetters.index(vonNeumanParts[i][1])
if napkin[1][digit][letter]:
rule += "".join(vonNeumanMapping[i])
return rule
rule = g.getrule()
#g.note(str((toNapkin(rule))[0][2]))
#g.note(str(vonNumanize(toNapkin(rule))[0][2]))
rule = golly.getstring("Enter text", toVonNeumanRule(vonNumanize(toNapkin(rule))))
#g.note(str((toNapkin(rule))[0][2]))
#g.note(str(mooreize(toNapkin(rule))[0][2]))
g.setrule(toMooreRule(mooreize(toNapkin(rule))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment