Author Topic: DNA language  (Read 6576 times)

Offline Lorgar

  • Bot Neophyte
  • *
  • Posts: 12
    • View Profile
DNA language
« on: May 07, 2011, 04:25:46 PM »
If I understand well; you can write a bot dna like this
cond
*.eye5 0!=
*.refeye 0 =
start
'deal with veggie
stop

start
*.eye5 0 !=
*.refeye *.myeye !=
*.refeye 0!=
start
'kill the dreaded foe with much bloodshed and slaughter
stop

cond
*.eye5 0 !=
*.refeye *.myeye =
start
'move away from siblings
stop
end

Or you can write it like this
start
If *.eye5 0 !=
 If *.refeye *.myeye !=
  if *.refeye 0 =
   start 'deal with veggy
   else deal with foe
  else 'deal with family
Else 'look around
stop
the problem is that I can not figure how I can translate it using "clearbool, dupbool, etc"
I dunno if I wrote it well, I did not use elseif things. If you see a mistake in either code, please point it out.

Offline Shasta

  • Administrator
  • Bot Destroyer
  • *****
  • Posts: 231
    • View Profile
Re: DNA language
« Reply #1 on: May 07, 2011, 04:49:42 PM »
I wrote a tutorial on the wiki about how to do this, not perfect, but should get you started.

Offline Lorgar

  • Bot Neophyte
  • *
  • Posts: 12
    • View Profile
Re: DNA language
« Reply #2 on: May 08, 2011, 06:37:10 AM »
I read it, but cant grasp a thing  :(
http://darwinbots.com/WikiManual/index.php/Inline_Conditions_Tutorial
first :
Can not see how the boolean stack work, do store action "use" the upper unit of the boolean stack? or does it remain un changed after the action has been made? What is the clearbool command use (if the boolean stack is cleared at the end of the cycle?) how do you make sure that this boolean value should be merged with this one to be used in the last statement, if they are not different? I printed it, read through and through for days but cant understand how you use it.

what I do not understand is all the complicated use of dupbool command, overbool etc, if a boolean value is not deleted when an action is made, why bother dup it if it stay where it is? why reduce the size of the boolean stack  if it is cleared after stop command? why not only use simple not command when you need an else?

If the boolean is evaluated before any action, does this evaluation delete the top unit of the boolean stack?
I read the tutos but still... (yes when I will have understood that I feel that I will be able to understand the tuto about conditionless bots).
why am I so stupid?

Offline Shasta

  • Administrator
  • Bot Destroyer
  • *****
  • Posts: 231
    • View Profile
Re: DNA language
« Reply #3 on: May 08, 2011, 04:58:36 PM »
Here is a quick example of how the boolean stack works. I put the action performed, and the state of the boolean stack one after another. The labels (A, B, C, etc.) are there to illustrate how some commands work, they are not truly there and have no effect. Note that this all happens while the DNA is being processed each cycle. These commands could all happen one after another in DNA and it would give the exact same result as I have written down here. Any command that does not operate on the boolean stack (store, add, shoot) will take place only if the top value on the boolean stack is true.

Code: [Select]
50 40 <
    (1) False - A
50 40 >
    (1) True - B
    (2) False - A
50 40 =
    (1) False - C
    (2) True - B
    (3) False - A
overbool
    (1) True - B'
    (2) False - C
    (3) True - B
    (4) False - A
and
    (1) False - (B' and C)
    (2) True - B
    (3) False - A
dupbool
    (1) False - (B' and C)
    (2) False - (B' and C)
    (3) True - B
    (4) False - A
not
    (1) True - (not (B' and C))
    (2) False - (B' and C)
    (3) True - B
    (4) False - A
or
    (1) True - ((B' and C) or (not (B' and C))
    (2) True - B
    (3) False - A
swapbool
    (1) True - B
    (2) True - ((B' and C) or (not (B' and C))
    (3) False - A
dropbool
    (1) True - ((B' and C) or (not (B' and C))
    (2) False - A
true
    (1) True - D
    (2) True - ((B' and C) or (not (B' and C))
    (3) False - A
clearbool
    (empty)

Offline Lorgar

  • Bot Neophyte
  • *
  • Posts: 12
    • View Profile
Re: DNA language
« Reply #4 on: May 09, 2011, 05:57:01 AM »
I understand this, but when an action take place, will it automaticaly delete the top value of the boolean stack?
If when reaching start there are two or more values on the boolean stack, first action will use the first, delet it then use the second for the second action?

Offline ikke

  • Bot Destroyer
  • ***
  • Posts: 300
    • View Profile
Re: DNA language
« Reply #5 on: May 09, 2011, 12:24:23 PM »
no the values on the stack stay there until removed by clearbool(clears the entire boolean stack) or dropbool (removes the first from the stack)

Offline Lorgar

  • Bot Neophyte
  • *
  • Posts: 12
    • View Profile
Re: DNA language
« Reply #6 on: May 09, 2011, 01:54:00 PM »
so, the problem is, how can I create the right combination of boolean command to combine two genes in one.
like this
Code: [Select]
cond
*.eye5 0 =
start
'look around
stop

cond
*.eye5 0 !=
*.refeye *.myeye !=
start
'jump at the foe
stop

cond
*.refeye 0 =
start
'eat the lettuce
stop
end
can I make some code like
Code: [Select]
cond
*.eye5 0 !=
*.refeye *.myeye !=
*.refeye 0 =
start
'eat the lettuce
else jump at the foe
else look around
using boolean commands?

edit : yes I can, as described in the tuto, but I do not understand How you build all the dropbool, and, not structure beforehand. Using tables? I would like to know the design process step by step...
« Last Edit: May 09, 2011, 01:57:42 PM by Lorgar »

Offline Shasta

  • Administrator
  • Bot Destroyer
  • *****
  • Posts: 231
    • View Profile
Re: DNA language
« Reply #7 on: May 10, 2011, 12:00:08 AM »
Ok, so the goal is to take these three genes:
Code: [Select]
cond
*.eye5 0 =
start
'look around
stop

cond
*.eye5 0 !=
*.refeye *.myeye !=
start
'jump at the foe
stop

cond
*.refeye 0 =
start
'eat the lettuce
stop
end
and turn them into one.

So, lets look at the shared conditions. *.eye5 0 = and *.eye5 0 != will always be opposite one another, one true, one false. This means we actually only need one of them, the other two conditions are similar, but have a large enough twist that they must be computed separately. Now lets set up the first condition.

Code: [Select]
start
*.eye5 0 =
    'look around
stop

Now, to add in the next conditions / actions we are going to reuse the value that is already on the boolean stack.
Code: [Select]
start
*.eye5 0 =
    dupbool not 'duplicates and inverts the top value on the stack
        *.refeye *.myeye != and 'adds a new value to the top of the stack and combines it with the inverted value
            'jump at the foe
    dropbool 'remove the top value from the stack, we now only have the value of *.eye5 0 = on the stack
    dupbool not 'duplicate and invert our initial condition again
        *.refeye 0 = and 'same as before
            'eat the lettuce
    dropbool 'returns to initial condition
        'look around
stop

This code can be simplified a touch by using a single != and removing some of the nots but that's not a big deal.

Offline Lorgar

  • Bot Neophyte
  • *
  • Posts: 12
    • View Profile
Re: DNA language
« Reply #8 on: May 10, 2011, 08:34:01 AM »
ok, I understand, the advantage of this writing is the combinations of three genes in one.
now, what would they be over this way of writing : (not using the boolean stack)
Code: [Select]
cond
start
-2. shoot *.eye5 40 sub sgn add abs div mult store (if *.eye 5 40 > shoot what's in front)
stop

What are the pro and cons? :huh:
(edit) I would like to know when and why I would be better off using boolean stack maneuvers instead of integer stack ones. Since both knows no conditions they both save the condition reading price. I gather that in THIS lay all their interest..?
« Last Edit: May 10, 2011, 08:46:56 AM by Lorgar »

Offline Lorgar

  • Bot Neophyte
  • *
  • Posts: 12
    • View Profile
Re: DNA language
« Reply #9 on: May 13, 2011, 11:45:09 AM »
ok, after some thinking, I would say : the use of the boolean stack in action blocks reduce significantly the size of the gene and allow to combine several genes in one.
I do not know the nrg cost of looking into the boolean stack during an action.

not using the boolean stack at all would be better (if just looking in it cost something) but would make for much longer genes, that would be a weakness against mutation...