Author Topic: Mutation engine in bot code?  (Read 5014 times)

Offline MacadamiaNuts

  • Bot Destroyer
  • ***
  • Posts: 273
    • View Profile
Mutation engine in bot code?
« on: June 08, 2007, 09:08:48 PM »
With optisim or optimization sim I mean an evolution that doesn't change the DNA, but optimizes certain values, like % repro, nrg before repro, etc. Normal mutations are disabled, and all the changes are made within bot code.

Basically, at born, the new bot would inherit the values through racial memory (defaulting them if it missed), and modify them slightly.

At the end of the sim, DNA would look the same, but values would have reached an optimal value for that enviroment.

Animal Minimalis could be a good one to start. It has only 7 values to optimize.
« Last Edit: June 08, 2007, 09:26:29 PM by MacadamiaNuts »
Sometimes you win, and sometimes you lose...

Offline MacadamiaNuts

  • Bot Destroyer
  • ***
  • Posts: 273
    • View Profile
Mutation engine in bot code?
« Reply #1 on: June 08, 2007, 09:32:07 PM »
I modified Animal Minimalis so it uses .out1 and so, it allows cannibalism and speciation through evolution.

I'm running it now in two separated sims with teleporters set at once each 5000 cycles. (This is when a color sysvar would be quite handy...)

Code: [Select]
cond
*.robage 21 =
*990 0 =
start
0 971 store
30 972 store
50 973 store
0 974 store
314 975 store
3000 976 store
90 977 store
100 978 store
100 .out1 store
1 990 store
stop


cond
*.robage 21 =
*990 1 =
start
*971 2 rnd 1 sub add 971 store
*972 2 rnd 1 sub add 972 store
*973 2 rnd 1 sub add 973 store
*974 2 rnd 1 sub add 974 store
*975 4 rnd 2 sub add 975 store
*976 100 rnd 50 sub add 976 store
*977 2 rnd 1 sub add 977 store
*978 2 rnd 1 sub add 978 store
*978 .out1 store
stop



cond
*.eye5 *971 >
*.out1 *.in1 !%=
start
*.refveldx .dx store
*.refvelup *972 add .up store
stop

cond
*.eye5 *973 >
*.out1 *.in1 !%=
*.refage 20 >
start
-1 .shoot store
*.refvelup .up store
stop

cond
*.eye5 *974 =
*.out1 *.in1 %= or
start
*975 rnd .aimdx store
stop

cond
*.nrg *976 >
start
*977 .repro store
stop
end
« Last Edit: June 08, 2007, 10:53:39 PM by MacadamiaNuts »
Sometimes you win, and sometimes you lose...

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Mutation engine in bot code?
« Reply #2 on: June 08, 2007, 11:08:12 PM »
Neat idea, I'd like to know what happens with the bots.  I did some experiments with dom invincibalis (PYs bot) when I first joined DB.  Found that by playing with the reproduction nrg threshold, I could make the bot significantly stronger or weaker in a match.

You might want to make it so that there's a good chance of not changing any values.  Generally this is like a mutations, and something like 1 mutations pe generation is about as high as you want to go.  Otherwise you start dealing with a mutation meltdown and Muller's ratchet.
« Last Edit: June 08, 2007, 11:10:37 PM by Numsgil »

Offline MacadamiaNuts

  • Bot Destroyer
  • ***
  • Posts: 273
    • View Profile
Mutation engine in bot code?
« Reply #3 on: June 08, 2007, 11:44:52 PM »
I discovered that the %= operator is biased.

10% of 105 is 10, but 10% of 95 is 9.

Found that when I saw a bot happily feeding on another that just kept spinning.

So, bots that use lower out1 will have an advantage on those with higher out1, but then, they will be more aggresive against mutants.

If out1 goes below 10, they will attack all mutants. Yuck.
« Last Edit: June 08, 2007, 11:48:42 PM by MacadamiaNuts »
Sometimes you win, and sometimes you lose...

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Mutation engine in bot code?
« Reply #4 on: June 09, 2007, 12:45:16 AM »
The ~= and %= aren't great operators.  I'd recommend instead something like this:

val threshold sub abs targetvalue <=

Offline Endy

  • Bot Overlord
  • ****
  • Posts: 852
    • View Profile
Mutation engine in bot code?
« Reply #5 on: June 09, 2007, 03:55:31 AM »
Could do something like this for one of the cycles.

971 7 rnd add 50 store
*50 *

2 rnd 1 sub
*50 975 sub *50 976 sub mult
sgn abs mult
add

4 rnd 2 sub
*50 975 sub sgn abs 1 sub - mult
add

100 rnd 50 sub
*50 976 sub sgn abs 1 sub - mult
add

*50 store

Might want to disable waste in the sim to keep the values from being changed by it.

P.S.

Would the ~ or compliment, bit flip work to switch a one to a zero and vice versa? Wikipedia says it would but I've never experimented with ours.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Mutation engine in bot code?
« Reply #6 on: June 09, 2007, 05:21:01 AM »
It runs on twos-compilement.  I believe 0 ~ would be -1 actually.

Offline MacadamiaNuts

  • Bot Destroyer
  • ***
  • Posts: 273
    • View Profile
Mutation engine in bot code?
« Reply #7 on: June 09, 2007, 07:58:29 AM »
230000 cycles in each sim, 140 generations, sampled 12 bots out of 200:

Most bots developed a slight miopy. The value 971 ranges 1-10. Two bots had negative values (-5, -6).

They also increased the speed (972) from 30 to an average of 44.

The distance at were they start to shoot dropped from *.eye5 50 > to *.eye5 > 60.

The average distance to any friendly target before spinning to look around didn't change. The values were dispersed from -5 to 7.

The randomized amount of spin slowed a bit. In the sample appeared three genetic lines, one around 314, another around 308 (this line is more short sighted than the others, with values 9-10) and another around 297.

The amount of energy before reproduction didn't change in any meaningful way. The first line is split in two, one around 3250 and another around 2970, the second line is around 3150, the third line, 3050.

The reproduction rate was the less optimal. It went from 90 to 62! All but two ranged from 61 to 63. One was at 66, and another at 90, which means it cut its birth tie too soon.

The out1 value dropped to 90-98.
« Last Edit: June 09, 2007, 07:59:48 AM by MacadamiaNuts »
Sometimes you win, and sometimes you lose...

Offline MacadamiaNuts

  • Bot Destroyer
  • ***
  • Posts: 273
    • View Profile
Mutation engine in bot code?
« Reply #8 on: June 09, 2007, 11:14:37 AM »
Another option for this method would be to write down 20 genes and let evolution activate/deactivate them.

If racial memory 971 > 0, gene 1 activation condition would be true, and so on.
Sometimes you win, and sometimes you lose...

Offline MacadamiaNuts

  • Bot Destroyer
  • ***
  • Posts: 273
    • View Profile
Mutation engine in bot code?
« Reply #9 on: June 11, 2007, 10:04:21 AM »
1200000 cycles. Evolution isn't very fast paced, the changes happening aren't critical for survival, but long term advantages or disadvantages.

They are still between 1-10 for the first eye5 value.

Chasing speed increased again from 44 to 50. Sometimes if they don't run fast enough some other bots reach the veggie and block the sight.

The distance to start shooting kept decreasing, from 60 to 66. When they find a veggie they surround it, so being closer leaves less room for other bots, and blocks more vision angle.

The eye5 value to recognize and avoid friendly bots ranges from -1 to 1. I don't know why it's so narrow.

The max spinning speed is still 300 on average. In the sample there were two 317, from the same family branch, I guess. They don't like to stray away of that value, it seems.

The energy required for reproduction increased from 3200 to 4300. The energy for the offspring dropped a bit, to a well defined 50% average. It's a rigid DNA, this one, it doesn't modify its behaviour for age and size, so I think they can optimize it better with a tighter range of sizes.

Finally, the bot IDs decreased to 73-79. Any bot below 73 or over 79 would be killed.

Screenshot (I removed the second sim and placed an intrasim teleporter):

[attachment=597:attachment]

The background is from a photo of mine, I uploaded it to my site if you want to grab it:

http://www.franontanaya.com/descargas/imagenes/fishtank.jpg
Sometimes you win, and sometimes you lose...

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Mutation engine in bot code?
« Reply #10 on: June 11, 2007, 12:48:21 PM »
Quote from: MacadamiaNuts
The eye5 value to recognize and avoid friendly bots ranges from -1 to 1. I don't know why it's so narrow.

Which memory location do you mean?