# Random Targeting

A method of targeting that simply chooses a random angle among the angles that could possibly hit the opponent. Some successful NanoBots use this firing method. Its implementation is very small and for unpredictable movements, it will give a consistent hit percentage.

## Example

public void onScannedRobot(ScannedRobotEvent e) {
// ...

double bulletPower = Math.max(0.1,Math.random() * 3.0);
double escapeAngle = Math.asin(8 / Rules.getBulletSpeed(bulletPower));
double randomAimOffset = -escapeAngle + Math.random() * 2 * escapeAngle;

setFire(bulletPower);
// ...
}

## A simpler solution

A simpler method is to assume that the enemy is traveling in a circle around you (see Musashi Trick), which is often true among NanoBots and 1-vs-1 bots. If the enemy is traveling in a circle around you, the maximum distance it can cover before a bullet reaches it is enemy velocity / bullet velocity (in radians). For example, a power 3.0 bullet fired at an enemy going at full speed should be fired at a bearing offset between -8/11 and +8/11.

## Selecting firepower

The advantage of a random gun is that it should have a roughly equal hit rate against all types of Movement. This makes ideal firepower selection pretty easy to pre-calculate. In the following equations x is the choice of firepower. It is assumed that damage output per tick is the quantity you're interested in maximizing, it may not be.

Bullet damage, assuming firepower > 1:

$D=4x+2(x-1)$

The smallest size of a robot, in radians:

$s=\frac{36}{d}$, where $d$ is the distance to the other bot.

The total escape area, in radians:

$\alpha=2 \cdot asin(\frac{8}{20-3x})$

Probability of a hit, assuming uniform spread of bullets over $\alpha$:

$P=min(1,\frac{s}{\alpha})$

The expected damage from a shot:

$E=DP$

The heat created by a shot:

$H=1+\frac{x}{5}$

The firing frequency:

$F=\frac{1}{ceil(10H)}$

Expected damage $E_{x,d}$ per tick of combat:

$E_{x,d}=E \cdot F = D \cdot P \cdot \frac{1}{ceil(10H)} =\frac{(6x-2) \cdot min(1,\frac{16}{d \cdot asin(\frac{8}{20-3x})})}{10+ceil(2x))}$

Optimization of $E_{x,d}$ is left as an exercise for the coder.

v  d  e
Quick
Statistical
Log-Based
Heuristics
Hybrid
Firing Angle
Energy
Terms
Related