Author Topic: SS (Single Store) Bot Guide  (Read 5202 times)

Offline bacillus

  • Bot Overlord
  • ****
  • Posts: 907
    • View Profile
SS (Single Store) Bot Guide
« on: March 14, 2014, 06:47:14 PM »
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:

Code: [Select]
*.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:

Code: [Select]
*.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.

Code: [Select]
*.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:

Code: [Select]
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.

Code: [Select]
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):

Code: [Select]
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?  :huh:)

Step 3: Applying Conditions

Short and simple. Just string your conditions together, then multiply the target value by it:

Code: [Select]
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.

Code: [Select]
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:

Code: [Select]
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:

Code: [Select]
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.

Code: [Select]
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!
« Last Edit: March 14, 2014, 10:57:23 PM by bacillus »
"They laughed at Columbus, they laughed at Fulton, they laughed at the Wright brothers. But they also laughed at Bozo the Clown."
- Carl Sagan

Offline MysticalDumpling

  • Bot Destroyer
  • ***
  • Posts: 205
  • Kurwa chuj!
    • View Profile
Re: SS (Single Store) Bot Guide
« Reply #1 on: March 14, 2014, 06:53:50 PM »
Oh trust me, it does. Mweh heh heh
To być albo nie być, oto jest ze pytanie

Offline Peter

  • Bot God
  • *****
  • Posts: 1177
    • View Profile
Re: SS (Single Store) Bot Guide
« Reply #2 on: March 14, 2014, 07:00:52 PM »
Well done :cheers:
Oh my god, who the hell cares.

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
Re: SS (Single Store) Bot Guide
« Reply #3 on: March 14, 2014, 08:09:18 PM »
Good Job guys! This is brilliant!

Now the only thing we need to do is move this to the wiki(s).