# Chase Bullets/Implementations

Chase Bullets Sub-pages:
Chase BulletsImplementations

## Concept (by DBALL)

```package wiki;
import robocode.*;

{
double turns;
double time;

public void run()
{
}

public void onScannedRobot(ScannedRobotEvent e)
{
double distance = e.getDistance();
turns -= getTime() - time;
time = getTime();
if (turns <= 0) {
time = getTime();
turns = distance / 11;
setFire(3);
} else {
setFire((distance / turns - 20) / -3);
}
}
}```

## Concept (by Wompi)

The same concept as above, but it shots always with bulletdoubles if the distance is long enough. It's also independent from radarsweep, so you can put it in run() to.

```package wiki;

import robocode.ScannedRobotEvent;

{
double bTurns;

public void run()
{
}

public void onScannedRobot(ScannedRobotEvent e)
{
double distance = e.getDistance();

if (getGunTurnRemaining() == 0)  	// it's usefull to wait with shoting until the gun is in position
{
double timeDiff = bTurns-getTime(); // difference between last shot and now
if (setFireBullet((20 - distance/(timeDiff)) / 3) != null) // shot with bulletPower if ready, bulletPower depends on last shot
{
if (timeDiff <= (bTurns=0)) bTurns = getTime() + distance /11;    // if you shot with 3.0 bulletPower, calculate the turns when the bullet hit the target
}
}

//Test this against multiple sample.SittingDuck - then remove it and look what has changed :)
clearAllEvents();
}
}```

## Improved Concept (by Wompi)

By doing the math it turned out that you can simplify this to

```
....
double lastSpeed = Rules.getBulletSpeed(lastBulletPower);
double lastHeatTurns = Rules.getGunHeat(lastBulletPower)/getGunCoolingRate();
bPower = Math.min(Rules.MAX_BULLET_POWER,(20.0 - (e.getDistance()/((lastFireDistance/lastSpeed)-lastHeatTurns))) / 3.0);

if (bPower < 0.1) bPower = Rules.MAX_BULLET_POWER;

if (setFireBullet(bPower) != null)
{
lastFireDistance = e.getDistance();
lastBulletPower = bPower;
}
....```