DarwinBotsManual
Open the app EspañolES

Logic

The boolean stack operators: and, or, xor and not to combine conditions, true and false, and the tools to rearrange that stack.

Cost: Logic

OperatorWhat it does
andReplaces the top two values of the boolean stack with one: true only if both are.
orReplaces the top two values of the boolean stack with one: true if either is. The only way to ask for “this or that”.
xorReplaces the top two values of the boolean stack with one: true if exactly one of the two is.
notInverts the top value of the boolean stack: true becomes false and false becomes true. On an empty stack it gives false.
truePushes a true onto the boolean stack. Inside a gene's body, it re-enables the stores that a condition had blocked.
falsePushes a false onto the boolean stack. In a gene's condition it turns it off; in the body it blocks the stores that follow.
dropboolPops and discards the value on top of the boolean stack. Inside the body, it ends the effect of an inline condition.
clearboolEmpties the boolean stack. Since empty counts as true, every store that follows writes again.
dupboolDuplicates the value on top of the boolean stack. Good for saving a condition and using it again, for example to nest conditions in the body.
swapboolSwaps the top two values of the boolean stack. It lets you compute two conditions and choose which one rules each stretch of the body.
overboolPushes a copy of the second value of the boolean stack: a b becomes a b a. With a single value it pushes true.

The logic operators work only with the boolean stack, the stack of trues and falses that the comparisons fill. They don't touch the integer stack. They come in three kinds:

Between cond and start the one you need most is or, because the and is already supplied by start, which joins with and everything left on the boolean stack.

Inside the body of a gene they change roles: each store looks at the top value of the boolean stack and, if it is false, doesn't write (see Inline conditions). There not, true, dropbool and clearbool are used to decide which stores run. This bot moves forward if it sees something with the middle eye (.eye5) and, if not, turns; at the end it leaves the stack clean for the next gene:

' if it sees something, moves forward; otherwise turns
cond
start
  *.eye5 0 >
  20 .up store
  not
  60 .aimdx store
  clearbool
stop

One rule holds for all of them: an empty boolean stack counts as true. When an operator is missing an operand, it replaces it with true, and that's why some give surprising results with an empty stack or with a single value: not on an empty stack gives false, and or with a single value always gives true. Each page goes into the details, and the overview of the two stacks is in The integer and boolean stacks.

Each logic operator executed charges the cost Logic from the scenario settings.