Difference between revisions of "Blue Shift"

From Robowiki
Jump to navigation Jump to search
(just another example to get almost the same result - would be nice if someone can correct the spelling errors)
(deleted - and moved to chase bullets)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
Named after the [[wikipedia:Doppler effect| Doppler Effect]]
 
  
It is the same as {{OldWiki|BulletDoubling}} (Old Wiki)
 
[[File:Blue_Shift.JPG|thumb|200px|right|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).
 
 
 
----
 
<syntaxhighlight>
 
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);
 
}
 
}
 
}
 
</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>
 

Latest revision as of 16:46, 17 June 2012