Darwinbots Forum
Welcome To Darwinbots => Newbie => Topic started by: jknilinux on November 19, 2008, 06:25:44 PM
-
Hi everyone,
I was wondering if someone could show me the basics of inline conditions, or at least a link to a similar thread or tutorial. thanks!
-
Hi everyone,
I was wondering if someone could show me the basics of inline conditions, or at least a link to a similar thread or tutorial. thanks!
the best way is to create them by writing them out
for example (testing eye5 here
[div class=\'codetop\']CODE[div class=\'codemain\' style=\'height:200px;white-space:pre;overflow:auto\']*.eye5 50 sub sgn 1 sub sgn 1 add -1 mul .shoot store
10 -40 -1 -2 -1
50 0 0 -1 -1 (etc)
60 10 1 0 0
other usefull commands are floor abs sgn and mod
mod like in
*.robage 140 mod 130 sub sgn ==>>> etc to get something trigering after x cycles
or robage 51 mod 49 floor 49 sub...
there is a wikipage about this subject too, somewhere around here, do by writing yourself I think its more easy to understand.
-
It isn't the most effective way to get things done, but is the only way to get a decent bot down in one store .
Peter B, some quick suggestions:
-DB does have increment/decrement commands, so 1 add becomes ++ and 1 sub becomes --
-To make subtraction easier, use - instead of -1 mult
I posted a topic about conditionless logic in the DNA section a while ago, but am too lazy to find it myself.
-
I thought he ment inline conditions as in conditions inside genes.... but thinking about it, it does sound like he means conditions buildt into a single store...
If you want to see examples of Single Store (SS) bots, then look at the SS league... I think OneManBucket is well dokumented, and if you look for the topic in the starting gate containing Brevis then there's a lot of good tips on how to build and debug a SS bot.
If you mean inline conditions, like the ones used inside a gene (Not in the condition space) then they work just like regular conditions, but they won't get and'ed automaticaly.
The way it works is pretty straight forward, if you put something in the boolean stack while inside a gene then it will be a condition for the following lines in the same gene. The boolean used is always the one on top of the stack, so in order to have several conditions you need to and/or them together.
You can also overide any previous conditions by simply adding a new condition without and/or'ing it with the previous ones.
So if you write :
*.eye5 0 =
140 .aimsx store
*.nrg 100 >
40 .up store
Then the 2 conditions are not related, if eye5 is 0 you will turn, if you have over 100 energy you will move forward.
But if you write :
*.eye5 0 =
140 .aimsx store
*.nrg 100 > and
40 .up store
Then you will only move forward when eye5 is 0 and you have over 100 energy. The boolean stack will contain up to 20 booleans I think.
Then there's some additional operator that you can use, not, dupbool and dropbool can be usefull for cutting condition costs :
*.eye5 0 =
*.nrg 100 > and
*.robage 5 < or
140 .aimleft store
dupbool
*.body 50 < and
40 .up store
dropbool
dupbool
*.in1 123 = and
40 .dx store
dropbool
not
40 .aimright store
This will turn left if eye5 is 0 and you have over 100 nrg or if robage is less than 5. It will move forward if body is also less than 50.
If in1 is 123 and the first set of conditions was true then it will also move sideways (But the body size will be irelevant)
This is because the first set was duplicated before the body 50 < part was added, and then the top boolean was dropped, taking us back to the value from the first set of conditions.
In the end if the first set of conditions amounted to false we turn right.
Not sure I'm doing a good job at explaining this... I think theres a section on the wiki about the integer stack and how it works... the boolean stack is pretty much the same just with booleans... in the end it's just a stack (If you've worked with those before) like in any programing laguage... when you write a condition you push the result into the stack, but instead of poping values from it the top value is just used.
You can also read about the boolean operators on the wiki, generaly most of what you need is found on the sysvars and operators page.
(I currently find myself wishing the source was as welldocumented )
-
Sorry, I didn't know I was being vague. Basically, I wanted to make complex viruses, but since they can only be one gene long, I need to find a way to put conditional logic inside a regular gene. So what I needed was just info on the boolean stack and stuff.
Thanks for pointing me in the right direction! I'll figure out the rest.
-
A little bit late, but here is an example of Animal Minimalis as a one gene bot:
[div class=\'codetop\']CODE[div class=\'codemain\' style=\'height:200px;white-space:pre;overflow:auto\']'Animal_Minimalis
'By: Nums
'Good for mutation sims and for
'newbies to see how a basic bot works.
'Contains everything necessary for it
'to survive and reproduce.
' Gene 1 Food Finder
start
*.eye5 0 >
*.refeye *.myeye != and
''''''''
*.refveldx .dx store
*.refvelup 30 add .up store
' Gene 2 Eat Food
'''
*.eye5 50 >
*.refeye *.myeye != and
''''''''
-1 .shoot store
*.refvelup .up store
' Gene 3 Avoiding Family
'''
*.eye5 0 =
*.refeye *.myeye = or
''''''''
314 rnd .aimdx store
' Gene 4 Reproduce
'''
*.nrg 20000 >
''''''''
10 .repro store
stop
end
This is pretty basic, and really all you have to do is remove the cond/start statements, and be careful with your and statements. Once you start throwing in nested statements it gets a bit harder.
If *.eye5 0 !=
If *.refeye *.myeye !=
If *.refeye 0 =
'Deal with veggie
Else
'Eat
Else
'Deal with family
Turns into:
*.eye5 0 != dupbool
*.refeye *.myeye != and dupbool
*.refeye 0 = overbool overbool and
'Deal with veggie
dropbool
not and
'Eat
dropbool not
'Deal with family
(Pretty sure that is right, did it quick)
I may put up a tutorial on them in the wiki sometime.
-
(Pretty sure that is right, did it quick)
Its not.
I tryed it and it wont shoot but aproaches the alge
This is the code I used
'ANIMAL 1G
start
*.eye5 0 != dupbool
*.refeye *.myeye != and dupbool
*.refeye 0 = overbool overbool and
1 .up store
dropbool
not and
-1 .shoot store
dropbool not
300 rnd .aimdx store
stop
think there is a prob with the "not" function. please check, I can never get it to work
-
The bot actually does work as I have the conditions set up to, they just are not set up like you are thinking.
If *.eye5 0 !=
If *.refeye *.myeye !=
If *.refeye 0 =
'Deal with veggie
Else''''''''''''''''''''''''''''''''''''''''
'Eat
Else
'Deal with family
('''''ed for emphasis) In most/all programming languages Else sections only run when the IF statement before them failed. So, it is only trying to feed when the bot is NOT a veggie (one could use this to not kill a veggie and just feed a bit), so its actually doing exactally what you have it set up to do, push the veggies around and attack hunters.
So if you want to make it so the bot attacks everything thats not family remove the ''''''' lines
'ANIMAL 1G
start
*.eye5 0 != dupbool
*.refeye *.myeye != and dupbool
*.refeye 0 = overbool overbool and'''''''''''''''''''''''''''''''''''''''
1 .up store
dropbool''''''''''''''''''''''''''''''''''''
not and'''''''''''''''''''''''''''''''''''''''''
-1 .shoot store
dropbool not
300 rnd .aimdx store
stop
Also, a few tips to make it a bit more effective, put in a range check before it starts to shoot (*.eye5 < WhatEverDistanceYouWant), change the rotate value so it always makes a certain amount of turn (314 .aimdx is 1/4 of a revolution)
-
Wow, that's really helpful! Thanks Shasta!
-
Question / comment:
' Gene 2 Eat Food
cond
*.eye5 50 >
*.refeye *.myeye !=
start
*.refxpos *.refypos angle .setaim store
-1 .shoot store
*.nrg 100 >
-6 .shoot store
*.refvelup .up store
Stop
Will not result in a bot spraying -6 shots if nrg>100 regardless of the cond statement. Apparently either
a) everything between start and stop is only executed if cond is met
or
B ) the cond bool is anded with inline Booleans
Which is it?
-
a) everything between start and stop is only executed if cond is met
This is how it is, you can test it by putting something like this in.
cond
*.eye5 50 >
*.refeye *.myeye !=
start
314 .aimdx store
true
-1 .shoot store
stop
Wow, that's really helpful! Thanks Shasta!
Thanks, its not to bad once you have it figured out. This is actually how I have written most of my recent bots (though I do use a slightly less boolean stack based approach sometimes)
-
here is a large single gene bot I made.
There are more functions in it then I acutaly use.
Its kinda a construction kit for many of my bots.
what might be intresting of it are the various functions on top.
Note that where I use def. (which cannt be used in viruses I asume)
YOu can use direct memoery adressing
Like
25 .100 store
stores 25 at mem position 100
you can use it again by referencing *.100
-
Also, a few tips to make it a bit more effective, put in a range check before it starts to shoot (*.eye5 < WhatEverDistanceYouWant), change the rotate value so it always makes a certain amount of turn (314 .aimdx is 1/4 of a revolution)
I did know that. just wanted to see if it worked. way beyond animal minimalis. Working on neural nets now.
Edit: and thanks, you did help me