Skip to content

Instantly share code, notes, and snippets.

@tyleretters
Last active August 22, 2020 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyleretters/de61ee3d26f2347b1f0156e4f5b242af to your computer and use it in GitHub Desktop.
Save tyleretters/de61ee3d26f2347b1f0156e4f5b242af to your computer and use it in GitHub Desktop.
turing wip
-- 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
@tyleretters
Copy link
Author

tyleretters commented Aug 22, 2020

where it ended up, won't work outside the parent application (arcologies) but might be helpful for someone in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment