Before you touch a single rule, decide what you want your bot to do. Then turning that plan into rules is the easy part. Here is how to think it through.
The arena runs your brain every tick, many times a second. Each tick it does the same three things:
It is not a story that runs once. It is those three steps over and over, reacting to what is happening this instant. That is why a rule like "when the enemy is to my right, turn right" keeps aiming at a moving target: it re-checks dozens of times a second.
Say your plan in plain words, then ask one question for each behavior: "What should my bot do WHEN ___?" Every answer is a rule.
Plan: "Chase the enemy and hit it."
That is the whole brain: four rules, straight from four questions.
Rules run top to bottom, and the lower one wins. So put your "always" rules up top (your default behavior) and your "when the enemy is…" rules below, so they can override the default. "Always go straight" then "when the enemy is to my right, turn right" means: go straight, unless the enemy is to my right.
Do not write the whole brain at once. Add one rule, press play, and watch. Add the next. If something looks wrong, pause or slow it to ¼x and watch which rule glows: that is the one in charge right at that moment. Fix that rule, not the others.
Each of these is a real plan turned into rules. Open the Playground, pick it from the Rules tab's "Load an example" menu, slow it down, and watch the reasoning play out. Then try the tweak.
Reasoning: I win by landing lots of hits, so I want to be right on top of the enemy with my weapon on. Sense its direction, turn to face it, drive in, and always fire.
(Load it as "Charge and fire.")
Reasoning: a spinner does almost no damage until it is wound up. So keep it spinning, back off while it charges, and charge in only when it is at full speed.
(Load it as "Hit and run (spinner).")
Reasoning: I would rather outlast the enemy than trade hits. Attack while healthy, but retreat the moment I am hurt so I can repair, and only fire when something is in range.
(Load it as "Coward (flee when hurt).")
A brain is a function called botTick() that the arena runs every tick (many times a second). Each tick you read the situation and call commands to act. The whole thing is just:
function botTick() {
// read the situation, then decide what to do
}
| drive(n) | Move. 1 forward, -1 reverse, 0 stop. |
| turn(n) | Turn. 1 right, -1 left, 0 straight. |
| fire('name') | Run the named weapon. fire() with no name runs them all. |
| enemyDistance() | Distance to the nearest enemy. |
| enemyAngle() | Direction to the enemy. + = to your right, - = to your left, near 0 = dead ahead. |
| myHealth() | Your health, 0 to 100. |
| isFlipped() | true if you are on your back. |
| spinnerCharge() | How wound up your spinner is, 0 to 1. |
fire() when an enemy is close to save battery.myHealth() is low to retreat.spinnerCharge() to wind up before you commit to a hit.fire() when isFlipped() to try to self-right.