DarwinBotsManual
Open the app EspañolES

Writing to memory

The fourteen stores: the only words that change the bot's memory, and so the only way for it to do anything.

Cost: Store divided by the divisor of each one, only if it writes

OperatorWhat it does
storeStores a number at a memory address: it's how every command is given, like 20 .up store to move forward.
incAdds 1 to a memory cell: the cheapest counter in the DNA.
decSubtracts 1 from a memory cell: the cheap way to keep a countdown.
addstoreAdds a number to what is already in a cell, without having to read it first.
substoreSubtracts a number from what's already in a cell: the cell minus the value.
multstoreMultiplies what's in a cell by a number and stores the result right there.
divstoreDivides what is in a cell by a number, rounding to the nearest integer; dividing by 0 leaves the cell at 0.
ceilstorePuts a ceiling on a cell: if what it holds is greater than the number, it lowers it to that number.
floorstorePuts a floor under a cell: if what it holds is smaller than the number, it raises it to that number.
rndstoreReplaces what's in a cell with a random number between 0 and that value, with the same sign.
sgnstoreReplaces what's in a cell with its sign: −1 if negative, 0 if zero, 1 if positive.
absstoreStrips the sign from what is in a cell: a negative becomes positive.
sqrstoreReplaces what's in a cell with its rounded square root; if it isn't positive, it leaves it at 0.
negstoreFlips the sign of what's in a cell: 20 becomes −20 and −20 becomes 20.

Everything a bot does goes through these words. Moving, turning, shooting or reproducing is putting a number in a sysvar, and the only things that write to memory are the stores. They all share the following:

store is, by far, the most used: with it you give all the commands. inc and dec are the cheap counters (a tenth of the cost). The rest modify what is already in the cell without having to read it first: addstore, substore, multstore and divstore do arithmetic, ceilstore and floorstore set a ceiling or a floor, and rndstore, sgnstore, absstore, sqrstore and negstore transform the number that is stored.

They combine well on the same cell. This gene speeds up gradually and stops at a cap:

' asks for 2 more each cycle, up to 40
cond
start
 2 50 addstore
 40 50 ceilstore
 *50 .up store
stop

Cell 50 goes up 2, 4, 6… to 40 and stays there, and .up receives that value every cycle. It can also be done with *50 2 add 40 ceil 50 store, but that takes more words.

The full explanation, with the family table, which addresses can be written and when the engine acts on what was written, is in Writing to memory.