random-thinglike-things/ntdb/src/ntdbpkg/submodule.nim

43 lines
1.6 KiB
Nim

import NTtables
import strutils
# represents a 2d isotropic non-totalistic Moore neighborhood CA rule.
# each bit of b/s represents a transition.
# transitions start at the least significant bit and are
# in order from lowest number of neighbors to highest, alphabetically
# (w.r.t hensel notation)
# for example, 5 is "01e"
type INTRule* = object
b*: uint64
s*: uint64
# represents a "range" of rules.
# this is the set of all rules which have all the transitions of
# the minimum rule and no transitions that the maximum rule doesn't have.
# all evolutions of patterns have a rule range like this that they work in.
type INTRange* = object
min*: INTRule
max*: INTRule
# determine if a rule is within a rule range
proc inrange*(rule: INTRule, range: INTRange): bool =
# bitwise check for if all bits in the min rule are present in the given rule
# the parentheses are due to BEE where bee is
# xor somehow having a weird precedence and acting on a boolean without these.
if (rule.b xor range.min.b) != rule.b: result = false
elif (rule.s xor range.min.s) != rule.s: result = false
# bitwise check for if only bits in the max rule are present in the given rule
elif (rule.b or range.max.b) != range.max.b: result = false
elif (rule.s or range.max.s) != range.max.s: result = false
else: result = true
# converts a char digit to all transitions with that amount of neighbors
proc OTc(c: char): uint64 =
result = OTTable[int(c)-48]
# deprecated
proc parseOTfragment*(frag: string): uint64 =
for c in items(frag):
result = result or OTc(c)