This is all about balancing the stack.
Would it make more sense if the gene read like this?
cond
*.eye4 *.eye6 >
start
40 .aimsx store
4 .sx store
stop
Essentially that is all it does, but without wasting all that energy on store commands.
here is how it works in detail.
Assume that there is some junk on the stack. In Hunter 2.2 there will always be one junk value on top of the stack. I designed it that way.
I will explain the second gene in your list of 3
First of all the eyecell comparrissons add
two values then the ">" comparitor removes them both and sets the tag to execute the gene.
Next we use
mult to remove the top
2 values and replace them with
1. Clears one junk value. We don't
use it for anything. We just want it
goneSame thing again to clear a second junk value. If only
1 junk value is present then
1 junk value will be left. We can never get rid of that last one with mult, add, sub, div or any of the operators, but provided only
1 is left then no problem. That is what we want anyway.
Next we put a value of
40 onto the stack.
Then we put a value of
4 onto the stack.
end of gene!
So now, assuming that this gene was activated, we have the stack values as follows from top down.
4
40
junk value
Now we go through the rest of the turning genes. Some will be activated and some will not. If no other turning genes are activated then these values will still be on top of the stack when the
rotate gene is activated.
' rotate
' *******
cond
start
.sx store
.aimsx store
stop
This will store the top value
4 into .sx and the next value
40 into .aimsx so the robot will rotate and accelerate sideways in the same direction as its rotation, thereby nullifying some of its forward momentum (in the old direction. Remember that robots rotate
before accelerating).
if a further turning gene is activated, it will place the two eye values onto the stack. then remove them again immediately as before. This still leaves
4 and
40 as the top two values. We don't want these anymore as this second turning gene supercedes the earlier one. We need to remove and replace these before activating the
rotate gene so we use
mult mult to reduce the
3 values now on the stack down to
1 junk value. (as above)
now we can put our rotate and sideways acceleration values on top of the stack again.
In this way each turning gene deletes values left by previous turning genes leaving only those values placed there by the last gene to be activated.
In this way we can have any number of highly accurate rotations implemented on each cycle at very little cost. All you have to do is to make sure that you place them all in the correct hierarchy so that the last ones are more important than the first ones.
Coarse turning is done first followed by medium turning and finally fine turning to get zeroed in on robots that are in the inner eyes.
For more details please see my tutorial for 2.3.
You can find this at the
DarwinBots FTP server in the zip file "DarwinBots V2.3 Tutorial.zip"
In the tutorial, I show you how to use this technique for "SimpleBot", a demo robot that I build in stages.