[Home]UbaRamLT

Robo Home | Changes | Preferences | AllPages

This bot is based almost completely off the WaveSurfing Challenge bot B. I just wanted to make it quick so I copied someone else's LT gun. Sorry. --Bayen

package bayen;

import java.awt.geom.Point2D;

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

public class UbaRamLT extends AdvancedRobot{
	
	public void run(){
		setAdjustRadarForGunTurn(true);
		setAdjustGunForRobotTurn(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 enemyVelocity = e.getVelocity();
		
		
		double deltaTime = 0;
		double battleFieldHeight = getBattleFieldHeight(), battleFieldWidth = getBattleFieldWidth();
		double predictedX = enemyX, predictedY = enemyY;
		while((++deltaTime) * (8) < Point2D.Double.distance(myX, myY, predictedX, predictedY)){		
			predictedX += Math.sin(enemyHeading) * enemyVelocity;	
			predictedY += Math.cos(enemyHeading) * enemyVelocity;
			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()));
		deltaTime = 0;
		predictedX = enemyX;
		predictedY = enemyY;
                double turnAmt = theta;
                double moveAmt = Double.POSITIVE_INFINITY;
                moveWithBackAsFront(moveAmt, turnAmt);
		setTurnRadarRightRadians(Utils.normalRelativeAngle(absoluteBearing - getRadarHeadingRadians()));
		//setTurnRightRadians(Utils.normalRelativeAngle(theta - getHeadingRadians()));
		//setAhead(Double.POSITIVE_INFINITY);
		while((++deltaTime) * (11) < Point2D.Double.distance(myX, myY, predictedX, predictedY)){		
			predictedX += Math.sin(enemyHeading) * enemyVelocity;	
			predictedY += Math.cos(enemyHeading) * enemyVelocity;
			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;
			}
		}
		theta = Utils.normalAbsoluteAngle(Math.atan2(predictedX - getX(), predictedY - getY()));
		setTurnGunRightRadians(Utils.normalRelativeAngle(theta - getGunHeadingRadians()));
		//if(e.getDistance() < 200)
		fire(3);
	}
    void moveWithBackAsFront(double distance, double bearing) {
        double angle = Utils.normalRelativeAngle(bearing - getHeadingRadians());
	double turnAngle = Math.atan(Math.tan(angle));
        setTurnRightRadians(turnAngle);
        int direction = angle == turnAngle ? 1 : -1;
        setAhead(distance * direction);
    }

	
	
}

The first improvement I should do, is to do something like BackAsFront. Instead of sometimes turning more than 90 degrees at start, you then take the shortest path to where you want to go. -- GrubbmGait

Okay, improvement made! It really helped, so thanks. I just used the code in BackAsFront. Plus, it killed Dookious in a 10 round match (which doesn't mean much b/c it's only 10 rounds, but it means I'm improving!) --Bayen


Robo Home | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited February 20, 2006 21:05 EST by Bayen (diff)
Search: