I want to go over some pointers before I get into the good stuff. First, you will see me use square and square-root at places. There are two reasons why I do that:
1.) I need to convert from Area (2D) to value (1D)
2.) It just looks and feels better. We may need to play with these further though.
Second, I want to make changes to the Options Form layout as little as possible. In fact, if we go with my system we will not need to touch options form at all.
Finally, this is not what I want to see from chloroplasts, In fact, my views on chloroplasts where completely different. But, after talking to Shvarz, his system is actually pretty good.
Ok, here we go:
Attached is an excel file that shows visually all formulas described herein:
In an ideal world for plants, the amount of light they receive should be a constant. It is not. The two main factors that affect the amount of light a plant gets are
1.) Is it night or day?
2.) How much light is left available in the system?
The first one is easy to code for, we just base it on the current code. We need to start modifying the current code to code for the second.
Let us take a look at feedvegs in vegs.bas. I want to keep that subroutine and modify it. If we do that we can use the existing vegy options (Figure 1) and also we don't have to modify night and day options or even the pond mode options.
1.) We have to reprogram that subroutine so it works on all robots. Any robot can have chloroplasts after all. We still need to keep the veg distinction in the species structure so the system knows what robot to repopulate. I'll talk about that in detail later.
2.) Here is where it gets tricky. We have to start modifying after tok is calculated. The line you are looking for is:
If tok < 0 Then tok = 0
We need to figure out how much light we have available in the system. Acording to shvarz this is done by calculating the ratio of total available space in the current simulation (based on simulation dimensions) to the total area of all robots in the simulation.
Area Inverted = Total robot area / Screen area
Now we figure out the actual area to correct chloroplasts by.
Area correction = ( 1 - Area Inverted) ^ 2 * 4
Now we figure out how much chloroplasts the robot has based on 1 unit. I think 16000 chloroplasts should be equal 1 unit.
Chloroplast correction = Chloroplasts the robot has / 16000
Now we figure out the actual rate the robot is being fed. We multiply by 1.25 to offset the amount of energy lost for sustaining chloroplasts. 'tok' already exists in the subroutine as the feeding rate. We simply use it here.
Add energy rate = Area correction * Chloroplasts correction * tok * 1.25
Now we have to figure out how much energy it costs for sustaining chloroplasts:
Subtract energy rate = (Chloroplasts the robot has / 32000) ^ 2 * tok
Now we figure out the actual feeding rate. Let us cal acttok for simplicity:
acttok = Add energy rate - Subtract energy rate
The rest of the code should now use acttok instead of tok.
And that should be all the changes required for feeding vegys. Let us quicly take a look at mass and robot radios.
Shvarz has recommended to me that we apply chloroplast mass to the robot more gradually we square it here.
Added mass = (Chloroplasts the robot has / 32000) ^ 2 * 31680
We are not going to touch robot radios because there are limits to the distance ties can stretch and ties are calculated from the robots center. I think we should have an indicator for chloroplasts like the indicator for shell or energy. Look into DrawRobPer.
Now let us talk about how the system will keep track of how much chloroplasts a robot has. I don't want a label in robot info to display the chloroplasts. I want an actual value in the DNA. This way we do not need to modify the vegy code to make the system recognize them as vegys. We just put the value on top of the dna, example:
'#chlr: 16000
cond
*.nrg
6000
>
start
50
.repro
store
15
.aimdx
store
stop
end
The value will be displayed in the dna when you click show dna and when you extract dna to file. When you set robots to 'repopulate' (called vegys in version 2.45.01) the system should ask you if you want to reset their chloroplasts to 16000.
The other reason is, there is a good chance some robots do not update their chloroplasts each cycle. I need a way of knowing how much chloroplasts a robot has at all times, this should not be epigenetic.
As far as the command, I think all we need is a simple .chlr variable in the 900s range that differentiates between read and write. Look at how I differentiate for tielen...tieang 1...4 in Update_Ties in Ties.bas. There are three stages:
1.) Input: Only change chloroplasts if flag was triggered (this cycle)
2.) Clear Input: Reset flag (this cycle)
3.) Output: current chloroplast levels stored back into memory (this cycle)
Also, look at the changes in DNAstore in the DNAexecution.bas to get the complete picture of this method.
I don't think we need share chloroplasts or anything like that because according to Shvarz it is not important to change energy when creating or destroying chloroplasts. Also, a baby will have exactly the same amount of chloroplasts as its mama.
Also make sure you add chloroplasts to SaveRobotBody and LoadRobotBody in HDRoutines.bas so that chloroplasts are saved as part of the simulation file if anyone wants to resume a simulation later and for debugging purposes.
Now let us talk about the robot repopulation. I want to keep it the same as it currently is (Figure 2) for the options form. What it does however, will be a little different.
We need to calculate the total amount of chloroplasts across all robots / 16000. Let us call this 'allchlr'
sudo:
If allchlr > Max avg. vegys Then do not let vegys reproduce
If allchlr < Repopulation threshold avg. vegys Then the repopulate vegys using current repopulation rules. (Robots per repopulation event and repopulation cool down period)
(edit: By 'vegys' here, I mean repopulating robots, sorry for the small confusion)
The main change here is that repopulation is no longer a static value. It depends on how much total chloroplast is on the screen. Hopefully, this will lead to robots evolving their own chloroplasts and not being depended on 'repopulating' robots at all because the system only repopulates when non-repopulating robots do not use chloroplasts.
I tried to make my explanation as clear as possible, if you have any further questions let me know. Please, if you decide to code this stuff in, use the revision currently in the trunk in the svn, I submitted all my latest updates this morning.