Chase Bullets/Implementations

From Robowiki
< Chase Bullets
Revision as of 16:45, 17 June 2012 by Wompi (talk | contribs) (code snippets for chase bullets)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Chase Bullets Sub-pages:
Chase BulletsImplementations

Concept (by DBALL)

package wiki;
import robocode.*;

public class BlueShift extends AdvancedRobot
{
	double turns;
	double time;

	public void run()
	{
		setTurnRadarRightRadians(Double.POSITIVE_INFINITY);
	}

	public void onScannedRobot(ScannedRobotEvent e)
	{
		double absoluteBearing = e.getBearingRadians() + getHeadingRadians();
		double distance = e.getDistance();
		setTurnRightRadians(robocode.util.Utils.normalRelativeAngle(absoluteBearing - getGunHeadingRadians()));
		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.AdvancedRobot;
import robocode.ScannedRobotEvent;

public class Bilby extends AdvancedRobot
{
	double bTurns;
	
	public void run()
	{
		setTurnRadarRightRadians(Double.POSITIVE_INFINITY);
	}
 
	public void onScannedRobot(ScannedRobotEvent e)
	{
		double absoluteBearing = e.getBearingRadians() + getHeadingRadians();
		double distance = e.getDistance();
		setTurnGunRightRadians(robocode.util.Utils.normalRelativeAngle(absoluteBearing - getGunHeadingRadians())); // head-on gun

		setTurnRadarLeftRadians(getRadarTurnRemainingRadians()); // just a simple RadarLock

		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;
    }
    ....