Code center > Suggestions
Nested Conditions
Numsgil:
This is one of those things that have bugged me to no end.
The only thing that Darwinbots can't do smoothly in the DNA (well, there are some others too, but this is a big one) is nested conditions. Things like:
if nrg > 4000
if age > 2000
'do stuff for age > 2000 and nrg > 4000
else
'do stuff for age <= 2000 and nrg > 4000
end if
There are ways around this, but they tend to be messy and ineligant.
Anyway, this is how I'm thinking to modify the DNA flow control structure to allow nested conditions.
When the program comes across the first cond statement, it checks if it's true or false. If it's false, it finds the next stop statement that doesn't have a corresponding cond.
That's probably confusing. It's like this (cond in this represents an entire condition like we're used to):
cond <-evaluates to false, read until 1 stop is found
cond <- will not be evaluated, read until 2 stops are found
stop <- one stop found, read until 1 stops are found...
cond
stop
cond
stop
stop <- stop found, start normal execution again.
If cond evaluates to true:
cond <-- evaluates to true
cond <--evaluates to false
some code in the middle <-- isn't executed
stop
cond <-- evaluates to true
some junk DNA that isn't executed
start
program code that's executed
stop
cond <--evaluates to false
start
<--some code that isn't executed
else
code that's executed
stop
stop
I think that demonstrates all of it. (<-- are comments if you didn't catch that...)
so basically stop now hooks up with cond instead of with start and else, and cond interrupts the flow of start and else.
not terribly difficult to do.
Allows nested conditions without breaking existing bots.
shvarz:
Before I address the proposed system: I really think we should make a rule of adding new features only if they allow something that is not possible without them.
As for your system, I see one major problem with it. It is going to tie a genome into a very specific structure, that is going to be almost impossible to mutate. Any mutation that does not introduce a corresponding pair of "cond" and "stop" is going to mess up the whole genome.
This is very obvious to me, cause I've done some web-site editing and the system of <open tag> blah-blah</close tag> has the same problems: you miss one <open> or </close> tags and the whole page goes to hell.
Here is another way to describe it: Imagine a formula with a lot of parenthesis, like:
2*(((2+2)*2)+2)*((2+(2*2-2))*2) Adding a new single parenthesis almost anywhere in this formula is going to drastically change the result of the formula.
Do you see the problem? Or should I explain it in more details. it is kind of an obvious thing to me and obvious things are sometimes the most difficult ones to explain :)
Numsgil:
Yes, I recognize the problem... A change way upstream could effect the entire genome.
When you describe it like that, it makes me think of the reverse polish notation the rest of the code uses. I wonder if there's something you could do with that...
Let me think on it for a while.
shvarz:
What is wrong with "cond start else" system we discussed before? Together with conditions stack that seemed to be quite adequate...
Numsgil:
You mean the system present in 2.4, or was there something else we discussed that I didn't implement?
It is adequate in the same way that writing without punctutation is adequate. For instance, in ancient writings. But all those "and"s and 'it came to pass"es get old after a while.
just because your wheel rolls doesn't mean you can't make it better. Like by strapping a rocket engine to it.
Navigation
[0] Message Index
[#] Next page
Go to full version