Difference between revisions of "Gene"
m (→How the DNA works) |
m (→Another Explanation: links) |
||
(3 intermediate revisions by one other user not shown) | |||
Line 50: | Line 50: | ||
---- | ---- | ||
− | == | + | ==Another Explanation== |
− | + | ||
− | + | This explanation is a kind of translation Darwinbots source code into English. | |
− | + | ||
− | * [[ | + | DNA code is parsed into several parts which may have their own context. There are commands, which define the current context. |
+ | |||
+ | # <tt>COND</tt> context starts with <tt>[[cond]]</tt> and lasts until <tt>[[start]]</tt>, <tt>[[else]]</tt>, <tt>[[stop]]</tt> or <tt>[[end]]</tt>. | ||
+ | # <tt>BODY</tt> and <tt>ELSEBODY</tt> contexts start with <tt>start</tt> and <tt>else</tt> accordingly and last until <tt>cond</tt>, <tt>start</tt>, <tt>else</tt>, <tt>stop</tt> or <tt>end</tt>. | ||
+ | # Anything else is <tt>CLEAR</tt> context (no commands are executed at all). | ||
+ | |||
+ | Whether other commands are executed depends on the context. | ||
+ | |||
+ | # Push stack, [[Basic_Commands|basic]], [[Advanced Commands|advanced]] and [[Bitwise_Command|bitwise]] commands are executed everywhere except <tt>CLEAR</tt> context. They operate on the integer stack. | ||
+ | # [[Logical Comparison Operators|Conditions]] and [[Logic|logic commands]] are executed inside <tt>COND</tt> context only. | ||
+ | #* Conditions take values from the integer stack and put results in the boolean stack. | ||
+ | #* Logic commands operate with the boolean stack solely. | ||
+ | # [[Store_Commands|Stores]] work in <tt>BODY</tt> and <tt>ELSEBODY</tt> contexts. They operate on the integer stack and the memory. | ||
+ | #* Stores in <tt>BODY</tt> context are executed either if there are no values in the boolean stack, or if <tt>and</tt>'ed values in the boolean stack equal <tt>true</tt>. | ||
+ | #* Stores in <tt>ELSEBODY</tt> context are executed, if <tt>and</tt>'ed values in the boolean stack equal <tt>false</tt>. | ||
+ | |||
+ | The memory and the integer stack is persistent during a single cycle. It means, that if you leave a value in the integer stack in one gene, it will be still there when you enter the next gene. The boolean stack is cleared each time <tt>start</tt>, <tt>else</tt> or <tt>stop</tt> is met. | ||
+ | |||
+ | {{DNA}} |
Latest revision as of 21:30, 2 December 2007
1 Genes - The Darwinbots Language
1.1 Overview Darwinbots uses a simplified programming language, which admits no conditional jumps or cycles.
The idea is that of programs made up by daemons, that means closed parts waiting silently until a particular event happens, and then activating to perform some task. These parts are called 'genes'. A robot's program, a DNA, is made only by a sequence of genes, all waiting for their own particular event to activate them. This event is specified at the head of the gene. If a gene is activated, then his body is executed. A gene's body consists in a straight sequence of instructions, without cycles or jumps, doing some operations on the robot's memory. After the body execution is complete, the gene turns silent again, until something wakes it up again.
1.1 The Code A gene looks like this (keywords in bold):
cond :head start marker
activation conditions
start :body start marker
task to perform
stop :gene end marker
cond
start
stop
and a complete dna will look like
gene
gene
.....
gene
end DNA end marker
1.1 Flow control:
cond: marks the beginning of the gene, and also the beginning of his activation condition.
start: marks the beginning of the body part of the gene
stop: marks the end of the body part of the gene, as well the end of the whole gene.
end: marks the end of the dna.
Another Explanation
This explanation is a kind of translation Darwinbots source code into English.
DNA code is parsed into several parts which may have their own context. There are commands, which define the current context.
- COND context starts with cond and lasts until start, else, stop or end.
- BODY and ELSEBODY contexts start with start and else accordingly and last until cond, start, else, stop or end.
- Anything else is CLEAR context (no commands are executed at all).
Whether other commands are executed depends on the context.
- Push stack, basic, advanced and bitwise commands are executed everywhere except CLEAR context. They operate on the integer stack.
- Conditions and logic commands are executed inside COND context only.
- Conditions take values from the integer stack and put results in the boolean stack.
- Logic commands operate with the boolean stack solely.
- Stores work in BODY and ELSEBODY contexts. They operate on the integer stack and the memory.
- Stores in BODY context are executed either if there are no values in the boolean stack, or if and'ed values in the boolean stack equal true.
- Stores in ELSEBODY context are executed, if and'ed values in the boolean stack equal false.
The memory and the integer stack is persistent during a single cycle. It means, that if you leave a value in the integer stack in one gene, it will be still there when you enter the next gene. The boolean stack is cleared each time start, else or stop is met.
How the DNA works
- Genes
- Execution Flag
- The Stack
- Custom labels (or variables if you prefer)
- Order of actions