A vegetable
Step by step, a vegetable that makes its own chloroplasts, lives off the sun and fills the field with children: why to turn when splitting, what happens at night and how the world repopulates it.
In A bot that moves you built a bot that moves, and in A bot that looks for food, one that goes hunting the others for food. This tutorial plays for the other team: a vegetable that chases no one. All its energy comes from the sun, and with it it fills the field with copies of itself. As always, each step adds a gene to the DNA and tells you what you should see.
What a vegetable has
A vegetable is a bot of a species you marked as such: the Is a vegetable (photosynthesizes) checkbox when editing the species in Experiment, or Vegetable (photosynthesizes) when seeding from Observe.
With that mark, the world treats it differently:
- It's born with Starting chloroplasts chloroplasts (16000 in the app).
- It doesn't suffer shock when it loses energy all at once (Energy, body and waste).
- Its children are vegetables too.
- Its population has a cap, and the simulation tops it up when it runs short.
Photosynthesizing, on the other hand, isn't exclusive to vegetables: any bot with chloroplasts does it. How photosynthesis works, when there's sun and how much it yields is in Chloroplasts and vegetables; here we use it.
Step 1: make chloroplasts
In the app, a freshly seeded vegetable already comes with its 16000 and grows without you writing a single line. But chloroplasts get lost on their own, are split with each child and each one weighs something, so the serious algae of the Bestiary make their own. Let's do the same:
' Makes chloroplasts while there's free light left over
cond
*.chlr *.light <
start
160 .mkchlr store
stop.chlr says how many it has and .light, how much free light is left in the field: when bots are plentiful, each one covers its own patch and the light drops. While the free light exceeds the chloroplasts it has, the gene buys 160 per cycle with .mkchlr; once the chloroplasts catch up with the light, it switches itself off. Removing them with .rmchlr is free, but gives nothing back.
Buying costs New chloroplast per chloroplast. With costs turned off you don't notice; with the F1 league price (0.2), an alga that started with 3000 finished building its factory with about 6140 less energy than a twin with costs at 0: exactly what the chloroplasts cost it. And since a purchase is canceled entirely if it would leave the bot with less than 100 energy, an alga that starts poor can't afford the luxury: in the test, one that was born with 500 spent its first 200 cycles stuck at the floor of 100, buying little by little what the sun paid it.
What you should see: in the inspector, .chlr goes up by 160 per cycle until it reaches the free light, and there it stops. After each birth it starts again: the child takes half.
Step 2: live off the sun
With chloroplasts and in daytime, the bot gets paid every cycle, in the sun phase, the last of the cycle (see The cycle and the order of actions). The split is set by Photosynthesis: fraction to body: with 0.75, the app's value, a quarter of the gain goes to .nrg and three quarters to .body, at 10 for 1.
With solar energy at 100, a lone alga goes from 3000 to about 4660 energy in the first 100 cycles, and with the factory complete it gains about 225 per cycle between energy and body. Sooner or later it reaches the 32000 cap (Energy, body and waste): in the test it touched it before cycle 650, and from then on the sun kept shining for nothing. Accumulated energy that goes unused is energy thrown away; to make it count, you have to have children.
With the app's solar energy (10, Solar share per cycle), everything yields a tenth: the numbers at that value are in the table in Chloroplasts and vegetables.
Step 3: have children
When there's energy to spare, split. Second gene:
' With energy to spare, it splits
cond
*.nrg 6000 >
start
50 .repro store
stop.repro asks for a child that takes 50% of the energy, body, chloroplasts and waste (Reproduction). The number is the percentage, modulo 100, and the command stays written until the birth goes through. The child is born in front of the parent, facing it, in the births and deaths phase of the same cycle (Reproduction).
And here the problem of the still bot appears: a single birth. The child is born where the parent points and stays there; the next one wants to be born in that same spot, which is already occupied, and the birth fails. In the test, parent and child ended up locked face to face, the command stayed written retrying cycle after cycle, and at 500 cycles there were still two of them, full of energy and unable to split.
The solution is to turn between births, like the Bestiary's Alga minimalis does:
' With energy to spare, it splits and turns for the next one
cond
*.nrg 6000 >
start
50 .repro store
15 .aimdx store
stopBy turning with .aimdx, the spot of the next birth points somewhere else. With that turn alone, the population went from 1 to 2, 4, 8 and 12 bots in 500 cycles.
The complete bot
' A vegetable: makes chloroplasts, grows and multiplies
' Makes chloroplasts while there's free light left over
cond
*.chlr *.light <
start
160 .mkchlr store
stop
' With energy to spare, it splits and turns for the next birth
cond
*.nrg 6000 >
start
50 .repro store
15 .aimdx store
stopIn a long run it filled the field: 1 → 4 → 12 → 16 → 21 → 23 bots in 1500 cycles, and there it stopped by itself. It wasn't bad luck: with the field full, each bot covers the light of the others (Chloroplasts and vegetables), the free light dropped to less than half and the gain no longer reaches for more births. If in addition the chloroplasts of the whole field go over 90% of the cap, only one in eleven births goes ahead (Vegetable cap and Chloroplasts and vegetables).
Seed about fifteen copies marked as vegetable in the app and watch the field fill up with hexagons.
At night
By default it's always daytime. In Experiment, the Day and night control makes the sun set: each stretch lasts that value plus 1 cycles, and only the first day lasts one fewer (with 3: three of day, four of night, four of day…).
At night there's no photosynthesis: in the test, energy and body stayed pinned cycle after cycle while .daytime was 0. The purchasing gene doesn't find out (.light isn't recalculated at night) and the bot keeps buying in the dark: free with costs turned off, energy thrown away with real costs. The Bestiary's Chloroplastus buys by day and sheds them 1 at a time at night (Chloroplasts and vegetables).
The app's Day and night scenario brings 20 Alga minimalis and 5 Animal Minimalis with days and nights of 1000 cycles: watch the population oscillate every time the sun sets (Scenarios).
Repopulation
The world doesn't let vegetables disappear: if the chloroplasts of the whole field drop below Repopulate below (chloroplasts), every Cycles between repopulations cycles it seeds Vegetables per repopulation new vegetables. Mind the unit: the threshold counts chloroplasts, in units of 16000, not bots.
In the test, a lone vegetable with the threshold at 3 received 10 strangers at cycle 10 and another 10 at 20. Each one is born with 1000 body, the starting energy of its species and the chloroplasts of Starting chloroplasts, in a random spot. Of which species? Of a vegetable species that is still alive: if yours is the only one, the world seeds you with clones of yourself (Chloroplasts and vegetables).
Against the Bestiary's algae
Our bot is practically the Bestiary's Alga minimalis 3.0, which adds a slime gene:
' The slime gene of Alga minimalis 3.0
cond
start
*.nrg 500 div .mkslime store
stopEvery cycle it asks for as much slime as its energy divided by 500, computed with div and written to .mkslime, which gives ten slime for each point of energy. Slime stops shots and bites (Defenses). Running the real alga marked as a vegetable, in 300 cycles it went from 1 to 4 bots with about 22000 chloroplasts each and a layer of between 280 and 460 slime: the same life as ours, with armor.
Alga Substantis, on the other hand, takes the calendar seriously: by day it stores energy in the body with .strbody and goes around in circles; at night it draws from the body with .fdbody and gives birth to many small children, so that some of them reach the morning.
What to try next
- Follow the sun. With Random sun (weather) the sun is a strip that sweeps across the field: a still vegetable suffers seasons, one that moves can follow the light (Chloroplasts and vegetables).
- Give yourself defenses. The Alga minimalis's slime is the bare minimum; the Bestiary has vegetables with poison, like Alga Toxicus.
- Let someone eat you. Continue with A tie feeder, which builds a bot that feeds on your vegetable through a tie: only then does your alga stop being an exercise and real ecology begins.