I think it may be useful to explain here each piece of our own code, specially for those starting in 1G coding.
Here the bot:
http://www.darwinbots.com/Forum/index.php?showtopic=2168Lets go at it...
The Self-Mutation Enginecond
start
1 971 store
6000 972 store
50 973 store
50 974 store
100 975 store
10 976 store
stop
cond
start
*972 3 rnd 2 sub add 31900 ceil 972 100 rnd 99 sub 0 floor mult store
*973 3 rnd 2 sub add 5 floor 973 500 rnd 499 sub 0 floor mult store
*974 3 rnd 2 sub add 1 floor 974 500 rnd 499 sub 0 floor mult store
*975 3 rnd 2 sub add 0 floor 975 250 rnd 249 sub 0 floor mult store
*976 3 rnd 2 sub add 0 floor 976 500 rnd 499 sub 0 floor mult store
stop
Memory locations 971-990 are racial memory and they are inherited by offspring, so we store there key numeric values like amount of energy before reproduction, energy share during reproduction, max speed, etc.
The second block changes those values slowly over time, like point mutations do. I gave faster mutation rates to bigger values (500 rnd 499 sub 0 floor mult = 1 change chance each 500 cycles). You may mutate the variables at .robage = 0 too to simulate copy errors.
Robage-Id gene*.robage 1 add .out1 store
anything wherever *.in1 *.refage sub abs sgn 1 sub abs mult store
The first gene makes the visible variable in1 match the visible age of the bot. This way out1 keeps changing, is unique for each bot and can't be copied by other simple bots.
Then, we add the id check whenever needed. If they are equal, the sgn will return 0, otherwise will return 1.
Pack movement genes*.refveldx .dx *.eye5 sgn mult store
*.refaim *.aim sub 2 div *.aim add .setaim *.eye5 sgn mult *.in1 *.refage sub abs sgn 1 sub abs mult store
The first gene matches lateral movement of visible targets. This is really important either for following friendly bots or hunting enemy bots.
The second gene matches gracefully (or should) the friendly bot's aim. Packs don't trail each other, but move in the same direction.
Nine-eyes aiming-40 *.eye9 sgn mult -30 *.eye8 sgn mult add -20 *.eye7 sgn mult add -10 *.eye6 sgn mult add 10 *.eye4 sgn mult add 20 *.eye3 sgn mult add 30 *.eye2 sgn mult add 40 *.eye1 sgn mult add .aimsx store
There are many versions of this really old gene in the bestiary, check them. Basically, the purpose is to help the bot to get any object in the lateral eyes into the focus eye (eye5). You can store negative values in .aimsx. This gene adds and substracts amounts for each eye with anything in focus to allow it to aim at wider groups too. It makes packs more compact.
Instant aiming*.refxpos *.refypos angle .setaim *.in1 *.refage sub abs sgn mult *.eye5 sgn mult store
Another old gene. You get the coordinates of the non-friendly bot and calculate the aim angle. Note the id check, and the eye5 check (it would aim at the upper left corner if there wasn't anything on sight!). Note that currently (for 2.43a) this gene doesn't work for coordinates bigger than 32000.
Limited speed50 *.velup sub .up store
This gene will move forward your bot only the needed amount to reach a forward speed of 50. Note there isn't a limit here for lateral movement. You won't really need to limit lateral speed as long as you are changing it somewhere else or using fixpos.
Unfix and value restores0 .fixpos store
0 .eye5dir store
0 .eye5width store
Add those three genes at top of the code and they will keep your bot unfixed and with proper focus eye aiming and width. You can change the values later in the code.
Spatial awareness gene1200 .eye5width 4 rnd sgn 1 sub abs mult store
This is a very neat gene. For instant aiming and tieing the best is a full circle eye5, but full circle isn't good at all when you are surrounded of friendly bots, and you only need to instant aim or tie once. So here we check everything around the bot only once each 4 cycles on average.
Defensive cloud1200 rnd .aimshoot 60 *.eye5 sub sgn 0 floor mult store
This gene shots randomly around when there isn't anything nearby on focus. This is very effective if you are using venom, because it works on big, fast bots that trample over yours.
Venom blinding and strvenom killer exploit.eye5width .vloc store
.eye5dir .vloc 1 rnd mult store
.strvenom .vloc 1 rnd mult store
1000 .venval store
These genes set up venom shots. 50% of them will make the other bot to waste its energy storing the max amount of venom, then 25% will change its focus eye aim and 25% its focus eye width.
Selective shooting-3 .shoot *.nrg 1000 sub sgn 0 floor mult store
-3 .shoot *.in1 *.refage sub abs sgn mult *.eye5 60 sub sgn 0 floor mult store
-6 .shoot *.refeye sgn 1 sub abs mult *.eye5 60 sub sgn 0 floor mult store
The first gene will shoot venom only if the bot has more than 1000 energy. That's necessary if you are using the defensive cloud of shots, which is quite expensive.
Then, the second gene may override first if there is a non-friendly bot very close.
The third gene will shoot body feeding shots instead, if the bot that is close has zero eyes. That will be either an alga or a bot ruined by a virus.
Selective tieing77 .tie *.numties sgn 1 sub abs mult *.in1 *.refage sub abs sgn mult *.eye5 50 sub sgn 0 floor mult *.refage sgn mult store
100 .fixlen store
40 .stifftie store
This gene ties if:
a) the bot hasn't got any tie yet, to keep it clean.
B) the target isn't friendly.
c) the target is close.
d) the target isn't a newspawn.
Then, the other two keep the tie short and stiff.
Target lock1 .fixpos *.in1 *.refage sub abs sgn mult *.eye5 65 sub sgn 0 floor mult store
This gene will fix your bot when a non-friendly bot is within shooting range, thus nullifying any excessive speed.
Reproduction1256 rnd .setaim *.nrg 6000 sub sgn 0 floor mult store
50 .repro *.nrg 6000 sub sgn 0 floor mult store
Just 1G versions of classic reproduction genes. These activate when nrg is bigger than 6000.
Venom and poison stores100 *.venom sub .strvenom store
100 *.poison sub .strpoison store
These will keep 100 units of venom and poison stored and save energy when they are full.
Body maintenance*.nrg 10 div *.body sub .strbody *.nrg 1000 sub sgn 0 floor mult store
*.body 10 mult *.nrg sub .fdbody store
Classic genes with a little twist. When energy is below 1000, wasting it to make the bot bigger is a very bad idea.
Waste management*.waste .shootval *.waste 100 div abs sgn mult store
-4 .shoot *.waste 100 div abs sgn mult store
Here is a different way to check if a value is over a threshold. 100 div abs sgn returns 1 only if the value is bigger than 100. Put these genes at bottom of the code. When waste is over 100, they will override any other shoot command and shoot the excessive waste instead.
Share exploits95 .sharenrg store
99 .shareslime store
99 .shareshell store
These are the fastest way to transfer energy from the target to your bot, but be careful with your offspring if you use 99 .sharenrg.
Poison setup.shoot .ploc store
Share exploit - inverse*.tiepres .tienum store
.sharenrg .tieloc *.trefeye *.myeye sub sgn abs mult store
1 .tieval store
This does the same than 99 .sharenrg, but forcing the tied bot to do a 1 .sharenrg, as long as it isn't a friendly bot.
Untie friends*.tiepres .deltie *.trefeye *.myeye sub sgn abs 1 sub abs mult store
Unties friendly bots.
Antivirus*.thisgene 2 add .delgene store
*.thisgene 1 sub .delgene *.thisgene 1 sub sgn mult *.robage 10 sub sgn 0 floor mult store
Common antivirus, here for a 3 genes bot that deletes its first gene after 10 cycles.
Virus10 .vshoot *.vtimer sgn 1 sub abs mult *.nrg 1000 sub sgn 0 floor mult store
*.thisgene 1 add .mkvirus *.vtimer sgn 1 sub abs mult *.nrg 1000 sub sgn 0 floor mult store
stop
cond
*971 1 !=
start
*.thisgene 1 sub .delgene store
stop
This code shots virus as long as energy is over 1000. Remember that the shorter the virus, the faster the vtimer reloads. Here we use low energy virus (10), but shoot lots of them. The virus itself will check the racial memory for value 1 at 971 and, if it doesn't find it, will delete all genes.