Darwinbots Forum

Bots and Simulations => DNA - General => The Gene depository => Topic started by: MacadamiaNuts on August 10, 2007, 10:06:12 AM

Title: Lionfish's genes explained
Post by: MacadamiaNuts on August 10, 2007, 10:06:12 AM
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=2168 (http://www.darwinbots.com/Forum/index.php?showtopic=2168)

Lets go at it...

The Self-Mutation Engine

Code: [Select]
cond
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

Code: [Select]
*.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

Code: [Select]
*.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

Code: [Select]
-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

Code: [Select]
*.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 speed

Code: [Select]
50 *.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 restores

Code: [Select]
0 .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 gene

Code: [Select]
1200 .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 cloud

Code: [Select]
1200 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

Code: [Select]
.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

Code: [Select]
-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 tieing

Code: [Select]
77 .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 lock

Code: [Select]
1 .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.

Reproduction

Code: [Select]
1256 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 stores

Code: [Select]
100 *.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

Code: [Select]
*.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

Code: [Select]
*.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 exploits

Code: [Select]
95 .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

Code: [Select]
.shoot .ploc store
Share exploit - inverse

Code: [Select]
*.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

Code: [Select]
*.tiepres .deltie *.trefeye *.myeye sub sgn abs 1 sub abs mult store
Unties friendly bots.

Antivirus

Code: [Select]
*.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.

Virus

Code: [Select]
10 .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.
Title: Lionfish's genes explained
Post by: abyaly on August 10, 2007, 05:29:35 PM
Quote
.eye5width .vloc store
.eye5dir .vloc 1 rnd mult store
.strvenom .vloc 1 rnd mult store
1000 .venval store
The way you set up the probabilities in this is really elegant.
Title: Lionfish's genes explained
Post by: Numsgil on August 10, 2007, 08:01:56 PM
I've got to say, when we were first experimenting with conditionless DNA, I had no idea it would progress to this level of sophistication.  You shame Spanish Conquistador
Title: Lionfish's genes explained
Post by: MacadamiaNuts on August 10, 2007, 08:02:17 PM
To honor the truth, it was just lazyness....
Title: Lionfish's genes explained
Post by: Trafalgar on August 10, 2007, 10:10:06 PM
You could also make it randomly write to strpoison sometimes instead of strvenom, without too much extra code, like so:

Code: [Select]
.strvenom 1 rnd dup add add .vloc 1 rnd mult store
(25% chance to write strvenom, 25% chance to write strpoison, 50% chance to write nothing)

Sadly, attempts to speed up the operation by substituting two normally far faster operations* for the mult fail miserably. (Changing ".vloc 1 rnd mult" to ".vloc 1 rnd -- &", which would be replacing an operation that takes 30 or so CPU cycles with two that take about 1 cycle total, sadly, drops DB cycles-per-second nearly in half in a sim with 100 veggie test bots which have nothing but the above line (besides cond, start, and end) in its DNA. Presumably the extra overhead from interpreting an extra instruction is almost twice as great as the decrease in CPU time from changing the mult to something faster.)

* = The above is based on how slow multiplication is, compared to things like addition and bitwise math, on a pentium 4** in assembly language.

** = The x86 reference manuals were free from Intel when I ordered them several years ago. They've been very useful, but not at all remotely useful for DarwinBots stuff, as you can see from my example above.
Title: Lionfish's genes explained
Post by: Numsgil on August 11, 2007, 05:28:10 AM
The DNA virtual machine isn't really built to be efficient.  Every command has a function push and pop, which I imagine overpowers whatever the function is actually doing.

To be honest, it hasn't ever been the bottleneck before.  It's always been physics and vision which were taking up 75-80% of the CPU cycles.
Title: Lionfish's genes explained
Post by: MacadamiaNuts on August 11, 2007, 11:17:16 AM
That would be a nice challenge, to find the fastest version for common genes, since they can be written in so many ways.