Difference between revisions of "Blue Shift"

From Robowiki
Jump to navigation Jump to search
m (Using <syntaxhighlight>.)
(just another example to get almost the same result - would be nice if someone can correct the spelling errors)
Line 44: Line 44:
 
setFire((distance / turns - 20) / -3);
 
setFire((distance / turns - 20) / -3);
 
}
 
}
 +
}
 +
}
 +
</syntaxhighlight>
 +
 +
== Improved concept ==
 +
 +
The same concept, 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.
 +
 +
<syntaxhighlight>
 +
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();
 +
setTurnRightRadians(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();
 
}
 
}
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 13:53, 8 April 2012

Named after the Doppler Effect

It is the same as BulletDoubling (Old Wiki)

Example of waves that reach enemy at the same time

The picture to the right shows a group of waves clustered together.

How it Works

Fire a group of bullets that reach your target at the same time, either by moving the robot, changing bullet power, or a combination of both.


Concept

Use only on stationary targets (shows concept when farther away).



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

Improved concept

The same concept, 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();
		setTurnRightRadians(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();
	}
}