Comparisons
DNA's questions: they pop numbers from the integer stack and leave a true or a false on the boolean one. Equal, not equal, greater, less and the approximate comparisons.
Cost: Condition
| Operator | What it does |
|---|---|
< | a b < leaves true if a is less than b. The comparison for “hasn't reached yet”. |
> | a b > leaves true if a is greater than b. The one in *.eye5 0 >, “I see something”. |
= | a b = leaves true if the two numbers are equal. The one in *.eye5 0 =, “I see nothing”. |
!= | a b != leaves true if the two numbers are different. The one in *.refeye *.myeye !=, “it is not one of mine”. |
%= | a b %= leaves true if b is within 10% of a, limits included. With a negative a it is always false. |
!%= | a b !%= leaves true if b strays more than 10% from a. It is the exact negation of %=, so with negative a it is always true. |
~= | a b d ~= leaves true if b is within d % of a: an “about equal” with the margin you choose. Pops three numbers. |
!~= | a b d !~= leaves true if b strays more than d % from a. It is the negation of ~= and also pops three numbers. |
>= | a b >= leaves true if a is greater than or equal to b: like >, but the limit counts too. |
<= | a b <= leaves true if a is less than or equal to b: like <, but the limit counts too. |
Each comparison pops numbers from the integer stack and leaves one result, true or false, on the boolean stack. They read left to right: a b > asks “is a greater than b?”. There are three groups:
- Exact:
=,!=,<,>,<=and>=. These are the ones you will use most. - Approximate to 10%:
%=and!%=, for values that oscillate and should not be compared exactly. - Approximate with your own percentage:
~=and!~=, which pop a third number with the margin.
They almost always go between cond and start, where all the ones you put are joined with an and: the gene body runs only if all of them are true (Genes: cond, start, else and stop covers it). That is how you build a range with two comparisons. This gene runs only between cycles 10 and 20 of the bot's life (.robage), both included, and counts in cell 50 how many times it ran (11):
cond
*.robage 10 >=
*.robage 20 <=
start
50 inc
stopTo ask for “this or that” you have to combine them with or; the other logic words are in Logic. A comparison can also go inside the body, and then it decides whether the stores that follow it run: that is Inline conditions.
None of them fails: if the integer stack is short of numbers, they compare zeros. That is why = on an empty stack gives true (0 equals 0) and < gives false.
Every comparison executed charges the cost Condition from the scenario configuration.