Author Topic: Help with code-2  (Read 3672 times)

Offline shvarz

  • Bot God
  • *****
  • Posts: 1341
    • View Profile
Help with code-2
« on: December 11, 2006, 11:02:28 AM »
The program sees 3 genes in the following DNA:
Code: [Select]
pow 2 *.nrg start
 start
 rnd 300 ~=
 inc
 1 *-25 angle rnd dec
 4 *-386 *296 -17 .aimleft inc
 20 -5 6 else
 -- 1 floor inc
 cond
 -6 inc
 107

of which the second gene is always "on" and the first and third are always "off".  I don't understand how that happens.  Why is the first start ignored, while the second is used?  There are no conditions for any of them anyway.

Also, I always thought that conditions, such as ~= remove the numbers compared from the stack.  But if they do, then

rnd 300 ~= inc

would not result in reproduction.  But these bots reproduce just fine.
« Last Edit: December 11, 2006, 11:04:52 AM by shvarz »
"Never underestimate the power of stupid things in big numbers" - Serious Sam

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
Help with code-2
« Reply #1 on: December 11, 2006, 11:42:38 AM »
My DNA analysis carma is low at the moment, but what the hell.

conditions do remove both items off the integer stack and place the result on the boolean stack.

rnd 300 ~= inc

is not resulting in reproduction.  I think it must be the

rnd dec

that does it.

As far as the three genes, I think the first is between the two starts.  There is nothing there, so the 'gene' is always off.  The second is from the second start to the cond.  The else trips the FSM and tells the code that the cond is the start of a third gene which never has a start and so is always off.
« Last Edit: December 11, 2006, 11:43:04 AM by EricL »
Many beers....

Offline shvarz

  • Bot God
  • *****
  • Posts: 1341
    • View Profile
Help with code-2
« Reply #2 on: December 11, 2006, 12:03:28 PM »
I agree on your split of the genes, but that still does not explain how things work here.  "start" should get executed when conditions stack has "true" on it.  But there is nothing in this DNA that would put "true" on the condition stack.  So the second start should be ignored and no gene should executed ever.

Also, how would "rnd dec" result in reproduction?  At best that would put negative number into .repro and that should be ignored (I have not updated to the version where negatives are modded yet).  Also, this would result in a very inefficient reproduction, while my bots are dividing like crazy.

Could this indicate some bugs in how program reads DNA?  I could post my sim for you to check.
"Never underestimate the power of stupid things in big numbers" - Serious Sam

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
Help with code-2
« Reply #3 on: December 11, 2006, 12:32:17 PM »
I'll just cut and paste the bot.   I am certain there are bugs in the DNA display code and especially in the gene parsing.  You can see this as the bot properties dialog often differs from the DNA details w.r.t. number of genes.  I think the DNA details parse logic treats naked starts as true conditions.  This may differ from what the actual execution logic does.

If your not using the version that reproduces on negative numbers, then you got me.
Many beers....

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Help with code-2
« Reply #4 on: December 11, 2006, 04:13:44 PM »
Logical operators and conditions are ignored in the bodies of genes.  So the ~= does nothing because it's not in a condition.  It's basically junk DNA.

At the start of DNA the flags are set so that any starts encountered will be executed.  Thus the following DNA is possible:

start .repro inc

Which is the smallest reproducer I can imagine ever being created.  Also, a single cond can control multiple genes.  The following for instance:

cond *.nrg 5000 >
start
.repro inc
else
-1 .shoot store
start
1 .dn store

cond...

The last cond acts as both a stop command and a new cond statement.
« Last Edit: December 11, 2006, 04:15:36 PM by Numsgil »

Offline shvarz

  • Bot God
  • *****
  • Posts: 1341
    • View Profile
Help with code-2
« Reply #5 on: December 11, 2006, 04:33:10 PM »
Hmm, interesting...

And this makes me think that maybe we should modify the way conditions and genes work...  

Maybe we should not ignore logical operators in bodies of genes?  Seems a bit wasteful.  Why not let them place "true"s and "false"s on to the conditions stack?  In fact, this would allow to just drop the "cond" command all together.  Just write genomes like

2 1 >
start
.repro store


Also, I'm not sure how is it that a single condition can control multiple starts?  I thought the program took of the condition from the conditions stack every time it encountered start or else...
« Last Edit: December 11, 2006, 04:36:19 PM by shvarz »
"Never underestimate the power of stupid things in big numbers" - Serious Sam

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Help with code-2
« Reply #6 on: December 11, 2006, 04:53:10 PM »
When a cond statement is entirely finished, it's summed up into a single "cond" flag that alerts the program as to wether the next start or the next else statement should be executed.  This flag is only ever changed at the end of a cond statement.

Offline shvarz

  • Bot God
  • *****
  • Posts: 1341
    • View Profile
Help with code-2
« Reply #7 on: December 11, 2006, 05:33:21 PM »
Hmm, that's one way to do it.  I seem to remember discussions about a more mobile "conditions stack", where "true" and "false" statements would be placed by conditions and taken off by "start" and "else" commands.  And these statements could be operated by logical commands such as "and" and "or".  Am I hallucinating?    Or was that for the new version of DB?

I kind of assumed that this is how things work in DB now.  But I guess I was completely out of the loop.

I personally think that this way is much more flexible and powerful.  Seems like it would be a nice bonus for evolution, because it allows sloppiness in the code and evolution likes to be sloppy.  Am I missing something?
"Never underestimate the power of stupid things in big numbers" - Serious Sam

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Help with code-2
« Reply #8 on: December 11, 2006, 10:38:02 PM »
The conditions stack works inside a condition.  For instance, the comparison statements place boolean values onto the conditions stack.  At the end of the condition block, those conditions are all added up (and'ed together).

I don't see another way to do this that allows for multiple conditions in a single cond block -and- mantains backwards compatibilty.

I'm willing to entertain other ideas for a future DNA specification that doesn't need to be backwards compatible.