Suggestions, Hints, and Tips


Optimization of Code


The Stack

Remember, while the stack may be confusing, it can be quite useful. To recall a variable twice takes four instructions, while to recalll it once and duplicate it takes only three. Take for example this code that checks if a robot is in range and less than 65 pixels away:

Bad way:

Range 65 < Range and sub1 if

Good way:

Range dup 65 < and sub1 if

The second routine does the same thing as the first, but with eight instructions instead of nine. This may seem like a small thing, but saving a few instructions each chronon(Robowar's basic unit of time) can mean the difference between life and death when trying to pull off some crucial move.

Trigonometry

Using trig instead of long drawn-out routines can save lots of time in many situations. Let us take this code which determines if a robot's aim is mostly horizontal or horizontal:

Bad way:

Aim 45 > aim 135 < and aim 225 > aim 315 < and or horizsub if

Good way:

aim 100 sin 70 / horizsub if

Again, these routines do virtually the same thing, but this time the difference is overwhelming: twenty-one instructions versus eight! If this isn't enough proof to make you look for ways to optimize your code, I don't know what is! You end up defeating the purpose of having a fast processor in your robot by having inefficient algorithms. Please, for your own sake, optimize!.

General Improvements to Your Robots

Obviously, for a robot to be successful, not only must its code be efficient, but it must also employ a good strategy. Sitting in one spot and shooting does not cut it anymore.

Look at what other robots are doing. Do you see a common weakness? If you do, try writing a robot to exploit that weakness. Keep in mind however, it is not how a robot fairs against a select few, but against all opponents that really matters.