Creatures 1 Biology
(28 Aug 2022)
This guide is intended for those who are already familiar with the way creatures' biochemistry and biology functions, and want to get into the specifics of what happens during each tick. I recommend checking out these other resources to learn more:
- Creatures Wiki: Biochemistry
- Geatville: Medical, Muppetboy
Table of Contents
Increment biological clock
Run every 4 ticks.
Update brain
Run every 4 ticks if not dead or dreaming.
Add the Current Importance x 2 to the action lobe's current action neuron's state (to a max of 255).
Update biochemistry
Run every 4 ticks if not dreaming.
Update emitters
The signal for each emitter is equal to its source locus. If the emitter has the invert effect, the signal is equal to 255 minus the source locus value instead.
Only update if it's time based on the emitter's rate and the creature's biological clock, and if the signal is higher than the emitter's threshold value.
If the emitter's response type is digital, add its gain value to its corresponding chemical (to a max of 255).
If the emitter's response type is analogue, add the gain value multiplied by how much the signal is greater than the threshold (to a max of 255).
Lastly, if the emitter has the remove effect, set its source locus to zero.
Update receptors
The signal for each receptor is equal to how much the concentration of the receptor's chemical is over the receptor's threshold value, with a minimum of zero.
If the receptor's response type is digital and the signal is higher than zero, change the signal to be the receptor's gain value.
If the receptor's response type is analogue, multiply the signal by the receptor's gain value.
Lastly, increase the receptor's nominal value by its signal (to a max of 255). Unless it has the reduce effect, in which case reduce its nominal value by the signal (to a minimum of zero).
Update reaction sites
The availability of each of the reaction's two reactants is equal to the concentration of the reactant's chemical divided by the reactant's proportion value.
Take the lowest availability and decay it according to the reaction's rate. The difference between this value and the higher availability will be how much we modify the reaction's chemicals by.
Reduce the reactant chemicals the corresponding reactant proportion multiplied by the modifier.
Increase the product chemicals the corresponding production proportion multiplied by the modifier.
Update chemical concentrations:
Decay each chemical's concentration by its half-life rate.
Choose new action
Run every 4 ticks if not dead and not in the middle of a reflex action.
Choose a reflex
Look at each reflex with a signal and no latency to see if we should take one of them:
- Pick a random number between 0 and 255.
- If the reflex's signal is higher than that number, it's our chosen reflex.
- If another reflex's signal is higher than both its random number and the previously chosen reflex's signal, then it becomes the chosen reflex instead.
Meanwhile all reflexes with a positive latency value have their value decremented.
If a new reflex is chosen (one that isn't the current action) and we aren't asleep, execute the reflex and set Current Importance to zero.
Choose a voluntary action
Only if no reflex is chosen.
Look at all the voluntary actions we could take and choose the one with highest output from the Action Lobe.
If it's a new action:
- Reset the value of the old action's neuron to zero so it doesn't get repeated right away.
- Wake up if sleeping.
- Perform the action, with an 80% chance to announce it out loud.
- Add 10 to the action lobe's current action neuron's state (to a max of 255) to encourage the action to continue.
Update bacterium
Run every 128 ticks if creature is infected with a bacterium.
Update environmental stuff
Run every 128 ticks if not dead.
Set either hotness or coldness locus to current air temp (between -255 and 255, where negative values are cold and positive values are hot). The other locus gets set to zero.
Set light level locus to current light level (0-255, based on time of day).
Set crowdedness locus to 250 minus the distance a known creature is away from this one, to a mininum of 50. If there aren't any known creatures nearby, crowdedness locus is set to zero.
Update fertility stuff
Run every 128 ticks if not dead.
If the ovulate locus is less than 80, remove gamete (stop ovulating).
If the ovulate locus is more than 160, create gamete if there isn't one already.
Set fertility locus to 255 if gamete exists, 0 if it doesn't.
Set pregnancy locus to 255 if zygote exists, 0 if it doesn't.
Update aging stuff
Run every 128 ticks if not dead.
If the locus for a given life stage is positive, move to the next life stage. Express any genes that are tied to that life stage.
If aging out of the last life stage, or the die locus is set, then die.
Update goal object and action
Run every 128 ticks if not dead.
Only do this if not dead, sleeping, dreaming, or being carried.
Get the strength of each drive by multiplying its locus value by the corresponding value from the hierarchy of needs and dividing by 256.
- pain: 255
- hunger: 255
- coldness: 255
- hotness: 255
- fear: 255
- sex: 255
- tiredness: 220
- sleepiness: 200
- overcrowdedness: 200
- loneliness: 180
- anger: 180
- needforpleasure: 120
- boredom: 100
Look at each object type with an x position that the creature has a record for (ie. that the creature remembers seeing). Calculate the overall goal value of an object type by adding together the goal values for each drive - find what's listed in the creature's goal table for the object and drive, multiply it by the drive's strength, and divide by 256.
Pick the object type with the highest goal value. If there's no goal value higher than 32767, give up the search - we can check again next update. And if the creature is close enough to see an object of this type at the remembered location but it's no longer there, forget the position for that object type and give up the search for a goal object until next update loop.
If the object is in sight but the creature is not focusing on it, increase the state value of the Source Lobe neuron that corresponds to its object type by the highest drive's strength divided by four, in order to encourage the creature to focus on after all.
Now that we have a goal object, we can determine what action to take.
For each goal action, figure out its score based on the current situation, and pick the goal with the highest score. If none has a score higher than 9999, do nothing for now. To calculate the score:
- If creature is aware of a lift, "press the call button" gets -9 points. Otherwise the actions to push (activate 1) or pull (activate 2) the lift get -9 points each.
- If creature is aware of a call button that's been pressed, "press the call button" gets -9 points, "look at the call button to wait for lift" gets +8 points, and "travel east/west" get -1 point each. If the call button hasn't been pressed, no score modification. If they aren't aware of a call button at all, -9 points to "press call button" and "look at call button" and +1 point each to "travel west" and "travel east".
- If goal object is west of the creature, "travel west" gets +5 points and "travel east" gets -5 points. If the goal object is east, it's the reverse of that.
- If goal object is above the creature, "pull (activate 2) lift" gets +9 points, "press call button" gets +5 points, and "travel east/west" get +1 point each. If the goal object is below the creature, it's the same except "push (activate 1) lift" gets the +9 points instead of "pull".
- If current room type is Surface, "travel east/west" get +2 points each. Otherwise, "pull (activate 2) lift" gets +2 points and "press call button" gets +1 point.
Respond to the goal object and goal action as if the creature were responding to a spoken command. If a goal object is chosen and the creature already knows about it, its neuron in the Source Lobe gets increased by the highest drive's strength divided by four. If there's no goal object or the creature is already looking at it, increase the goal action's neuron in the Verb Lobe by the same value. If the creature isn't already looking at the goal object and needs to be, wait for the creature's attention to shift before doing this (and forget about it if they take longer than 5 attention-update cycles, where updates happen every 8 ticks).
Update instincts
Run every tick if dreaming.
Process first instict:
- Phase starts at 0 the first time through the processing loop for an instinct.
- If phase 0, stabilize the brain by setting every neuron's output and state to zero, and setting every dendrite's susceptibility to zero and its short-term weight to its long-term weight.
- If phase 35-39, reinforce instinct by setting instinct's reinforcer chemical to its reinforcement value.
If phase 1-39, apply instinct:
- Update biochemistry.
- Reset all neurons in the input and output lobes to have a state and output of zero.
- Stimulate the first neuron in the Perception Lobe, the second neuron in the Drive Lobe, and the third neuron in the Source Lobe, by setting their states to 255.
- If instinct has a motor neuron defined, set that neuron in the Action Lobe to have a state and output of 255.
- Update the brain.
If phase 40, fix memories by setting every dendrite's long-term weight to its short-term weight if its short-term weight is higher, and then stabilize the brain again. Processing is now complete.
- If phase 0-39, processing is not complete yet, so keep processing this instinct next tick with its phase incremented.
When processing of instinct is complete, remove it, and move on to next instinct.
If no instincts are left, stop dreaming.
Otherwise decrement dream counter, and stop dreaming if it hits zero.
Finally, increment biological clock.