I just got asked by MysticalDumpling to make a SS Bot guide. Sounded like a fun exercise, so I'll do my best, but bear in mind I haven't touched DB in around three years.

**The Inofficial SS Guide 1.0**

**Step 1: Conditions**The most important, and hardest part, of writing a SS bot, is writing up your conditions. I'll start with some simple examples and move from there:

`*.eye5 40 sub sgn 0 floor`

This statement is equivalent to

**.eye5 40 >*. How?

First, we subtract 40 from *.eye5; if *.eye5 was larger than 40, the value will be negative, if it was equal to 40, zero, and if it was less than 40, negative. the sgn operator reduces these possibilities to {-1, 0, 1}. Finally, the floor multiplier folds -1 and 0 into 0. End result is 0 if it's less than or equal, or 1 if it's greater.

Here's some more examples:

`*.refeye *.myeye sub sgn abs`

**.refeye *.myeye !=*. Same deal as before. the sub sgn reduces us to {-1, 0, 1}, depending on whether *.refeye is smaller, equal, or greater than *.myeye, respectively. abs turns -1 into 1, so we have 0 if they're equal, and 1 if they're not equal.

`*.refeye *.myeye sub sgn abs -- abs`

**.refeye *.myeye =*. The same example as above, but inverted.

**-- abs** is a very handy tool, as it inverts the result of a condition (i.e. it's our NOT operator).

**Step 2: Compounding Conditions**This step's actually fairly easy. Once you have all your conditions written out, you AND them together by multiplying their values, like so:

`2000 *.nrg sub sgn 0 floor`

*.refeye *.myeye sub sgn abs mult

39 *.eye5 sub sgn 0 floor mult

We'll only get 1 if both the conditions are one, otherwise the result is 0.

OR isn't much tricker. We add the conditions together and apply the

*abs *operator.

`2000 *.nrg sub sgn 0 floor`

*.refeye *.myeye sub sgn abs add abs

39 *.eye5 sub sgn 0 floor add abs

XOR's the only tricky one here. We need to check that the sum of the two conditions is exactly one.

*add -- abs* will give us 0 if that's true and 1 otherwise, so we invert it using the NOT operator (

**-- abs**):

`2000 *.nrg sub sgn 0 floor`

*.refeye *.myeye sub sgn abs add -- abs -- abs

39 *.eye5 sub sgn 0 floor add add -- abs -- abs

(Does this even come up?

)

**Step 3: Applying Conditions**Short and simple. Just string your conditions together, then multiply the target value by it:

`2000 *.nrg sub sgn 0 floor mult`

*.refeye *.myeye sub sgn abs mult

39 *.eye5 sub sgn 0 floor mult

**Step 4: Building Your Bot**The part you really wanted to get to! I honestly can't remember too much about this, so I'll give you the tools to string the bots together and leave it to someone else to write up some clues on writing good SS bots.

`cond`

start

'Values here

'Locations here

store

stop

This is your skeleton for every Single Store bot. For every potential store command, you'll need two corresponding blocks: one in the Values and one in the Locations. Same as any other bot really. I'll do a quick walkthrough of my first SS Bot, Dominis:

`cond`

start

'Values

-6

*.eye5 40 sub sgn 0 floor mult

*.refeye *.myeye sub sgn abs mult

'Locations

.shoot

*.eye5 40 sub sgn 0 floor mult

*.refeye *.myeye sub sgn abs mult

store

stop

Stores -6 into .shoot if:

- *.eye5 40 <
- *.refeye *.myeye !=

The way it works is that -6 and .shoot get pushed onto the stack and read by the store command if the conditions are true. Otherwise, 0 and 0 get pushed. The 0/0 is important, you'll see why next:

`cond`

start

'Values

-6

*.eye5 40 sub sgn 0 floor mult

*.refeye *.myeye sub sgn abs mult

5

2000 *.nrg sub sgn 0 floor mult

*.refeye *.myeye sub sgn abs mult

39 *.eye5 sub sgn 0 floor mult

add

'Locations

.shoot

*.eye5 40 sub sgn 0 floor mult

*.refeye *.myeye sub sgn abs mult

.up

2000 *.nrg sub sgn 0 floor mult

*.refeye *.myeye sub sgn abs mult

39 *.eye5 sub sgn 0 floor mult

add

store

stop

Same as before, but with 5 .up on the following conditions:

- *.eye5 40 >=
- *.refeye *.myeye !=
- *.nrg 2000 <

Note that due to the first condition, the two condition pairs are mutually exclusive and only (at most) one will return a non-zero value/location pair. This is what makes SS bots work - only one "gene" at a time must return a non-zero value; that way, when you add all the values up and add all the locations up, you get a sensible value pair. If more than one pair returns a non-zero value, then you get some jibberish (or worse yet, you don't) and waste the store command.

`cond`

start

'Values

-6

*.eye5 40 sub sgn 0 floor mult

*.refeye *.myeye sub sgn abs mult

5

2000 *.nrg sub sgn 0 floor mult

*.refeye *.myeye sub sgn abs mult

39 *.eye5 sub sgn 0 floor mult

add

50

*.nrg 2000 sub sgn 0 floor mult

39 *.eye5 sub sgn 0 floor mult

add

314 rnd

*.refeye *.myeye sub sgn abs -- abs mult

add

'Locations

.shoot

*.eye5 40 sub sgn 0 floor mult

*.refeye *.myeye sub sgn abs mult

.up

2000 *.nrg sub sgn 0 floor mult

*.refeye *.myeye sub sgn abs mult

39 *.eye5 sub sgn 0 floor mult

add

.repro

*.nrg 2000 sub sgn 0 floor mult

39 *.eye5 sub sgn 0 floor mult

add

.aimdx

*.refeye *.myeye sub sgn abs -- abs mult

add

store

stop

A turning and reproduction pair (I'll let you figure out the conditions), and we're done!

The only hint I can give regarding the design of your bot is to remember that you only have one store a cycle, so prioritize. Design your conditions in such a way that the most important functions take precedence. You don't want to starve to death because you're executing .up instead of .shoot if there's something in your sight.

Hope that helps!