-
-
Save tyleretters/de61ee3d26f2347b1f0156e4f5b242af to your computer and use it in GitHub Desktop.
turing wip
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
-- requires metabolism | |
-- requires probability | |
turing_trait = {} | |
turing_trait.init = function(self) | |
self.turing = {} | |
self.set_turing = function(self) | |
-- randomly seed, will typically only during instantiation | |
if #self.turing == 0 and self.metabolism > 0 then | |
for i = 1, self.metabolism do | |
self.turing[i] = fn.coin() == 1 | |
end | |
end | |
-- not an elseif becuase we'll then want to run the following | |
-- pad the register with falses when metabolism grows | |
if #self.turing < self.metabolism then | |
for i = #self.turing + 1, self.metabolism do | |
self.turing[i] = false | |
end | |
-- cut the end off of the metabolism shrinks | |
elseif #self.turing > self.metabolism then | |
for k,v in pairs(self.turing) do | |
if k > self.metabolism then | |
table.remove(self.turing, k) | |
end | |
end | |
end | |
-- check against the probability | |
if (math.random(0, 99) < self.probability) then | |
-- flip a coin to get our new value | |
table.insert(self.turing, 1, fn.coin() == 1) | |
-- remove the old value | |
table.remove(self.turing, #self.turing) | |
end | |
self.callback(self, 'set_turing') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where it ended up, won't work outside the parent application (arcologies) but might be helpful for someone in the future.