(redirected from WaveSurfingChallengeBotC)

[Home]WaveSurfingChallenge/BotC

Robo Home | WaveSurfingChallenge | Changes | Preferences | AllPages

Sits still and fires full power bullets using CircularTargeting. Source code is included. Written by David Alves and adapted for circular targeting by GrubbmGait.

/*
 * Created on Sep 17, 2004
 * Adapted on Jan 16, 2006
 *
 */
package wiki.challenge;

import java.awt.geom.Point2D;

import robocode.AdvancedRobot;
import robocode.ScannedRobotEvent;
import robocode.util.Utils;

/**
 * @author David Alves
 * adapted for circular targeting by GrubbmGait
 *
 * For more information about the Wave Surfing Challenge, visit
 * <a href="https://robowiki.net/perl/robowiki@WaveSurfingChallenge">https://robowiki.net/perl/robowiki?WaveSurfingChallenge</a>
 * 
 * This robot sits still and fires at its opponent using circular targeting.
 * 
 */
public class WaveSurfingChallengeBotC extends AdvancedRobot{

	double oldEnemyHeading;
			
	public void run(){
		setAdjustRadarForGunTurn(true);
		do{
			turnRadarRightRadians(Double.POSITIVE_INFINITY);
		} while(true);
	}
	
	public void onScannedRobot(ScannedRobotEvent e){
		double bulletPower = Math.min(3.0,getEnergy());
		double myX = getX();
		double myY = getY();
		double absoluteBearing = getHeadingRadians() + e.getBearingRadians();
		double enemyX = getX() + e.getDistance() * Math.sin(absoluteBearing);
		double enemyY = getY() + e.getDistance() * Math.cos(absoluteBearing);
		double enemyHeading = e.getHeadingRadians();
		double enemyHeadingChange = enemyHeading - oldEnemyHeading;
		double enemyVelocity = e.getVelocity();
		oldEnemyHeading = enemyHeading;
		
		double deltaTime = 0;
		double battleFieldHeight = getBattleFieldHeight(), battleFieldWidth = getBattleFieldWidth();
		double predictedX = enemyX, predictedY = enemyY;
		while((++deltaTime) * (20.0 - 3.0 * bulletPower) < Point2D.Double.distance(myX, myY, predictedX, predictedY)){		
			predictedX += Math.sin(enemyHeading) * enemyVelocity;
			predictedY += Math.cos(enemyHeading) * enemyVelocity;
			enemyHeading += enemyHeadingChange;
			if(	predictedX < 18.0 
				|| predictedY < 18.0
				|| predictedX > battleFieldWidth - 18.0
				|| predictedY > battleFieldHeight - 18.0){
				
				predictedX = Math.min(Math.max(18.0, predictedX), battleFieldWidth - 18.0);	
				predictedY = Math.min(Math.max(18.0, predictedY), battleFieldHeight - 18.0);
				break;
			}
		}
		double theta = Utils.normalAbsoluteAngle(Math.atan2(predictedX - getX(), predictedY - getY()));
		
		setTurnRadarRightRadians(Utils.normalRelativeAngle(absoluteBearing - getRadarHeadingRadians()));
		setTurnGunRightRadians(Utils.normalRelativeAngle(theta - getGunHeadingRadians()));
		fire(3);
	}
}


Robo Home | WaveSurfingChallenge | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited January 17, 2006 10:26 EST by GrubbmGait (diff)
Search: