[Home]Plains/Code

Robo Home | Plains | Changes | Preferences | AllPages

Difference (from prior author revision) (major diff, minor diff)

Changed: 4c4,5
//import java.util.Random;
import java.awt.geom.*;
import java.awt.Color;

Changed: 9,11c10,11
static private double lastEnergy=100,curEnergy=100,enemyGunHeat=100,turnAngle=0,favDistance,tryAmt=144;
static private java.awt.geom.Rectangle2D.Double _fieldRect = new java.awt.geom.Rectangle2D.Double(18, 18,
724, 564);
static private double lastEnergy,curEnergy,favDistance,tryAmt,myPrevEnergy?,dist;
static private final Rectangle2D.Double _fieldRect = new Rectangle2D.Double(18, 18, 724, 564);

Changed: 13,15c13,15
// static Random random=new Random();
static boolean frontTried=false,backTried=false;
static int timeSinceLastChanged?=50;
static private boolean tryingBack;
static private int timeSinceLastChanged?;
// double tempX,tempY;

Removed: 17d16
// java.awt.geom.Point2D.Double projectedPos=new java.awt.geom.Point2D.Double();

Changed: 20,21c19,21
favDistance=0d;

timeSinceLastChanged?=50;
energygain=new double[2];
tryingBack=false;

Changed: 27,33c27,29
//out.println(delta);
if(delta<=3.01 && delta>=0.09){
gain(delta);
double newVel=(Math.random()*40d) - 20d;
// out.println(newVel);
setMaxVelocity?(Math.abs(newVel));
setAhead(newVel*Double.POSITIVE_INFINITY);

if(delta<=3.01 && delta>=0.09){
move(0);

Changed: 35,37c31,39
timeSinceLastChanged?--;
if(timeSinceLastChanged?<=0){
if(frontTried && backTried){
if(--timeSinceLastChanged?<=0){
if(!tryingBack){
favDistance=Math.min(favDistance+=tryAmt*2d,575d);
tryingBack=true;
// out.println("Trying distance " + favDistance);
}else{
favDistance=Math.max(favDistance-=tryAmt*2.5,200d);
// backTried=true;
// out.println("Trying distance " + favDistance);

Changed: 39,40c41,43
if(energygain[0]>=energygain[1]){
favDistance+=tryAmt*2;
if(energygain[1]>=energygain[0]){
favDistance+=tryAmt*2d;
}

Changed: 42c45
}else{
// else{

Changed: 44c47
}
// }

Changed: 47c50
frontTried=backTried=false;
tryingBack=false;

Removed: 49d51
execute();

Changed: 51,61c53,58
if(!frontTried){
favDistance=Math.min(favDistance+=tryAmt,800);
frontTried=true;
// out.println("Trying distance " + favDistance);
}else{
favDistance=Math.max(favDistance-=tryAmt*2,50);
backTried=true;
// out.println("Trying distance " + favDistance);
}
timeSinceLastChanged?=120;
}
timeSinceLastChanged?=Math.max(100,(int)tryAmt*2);
}
if(Math.abs(dist-favDistance)<=tryAmt/2){
energygain[(tryingBack)?1:0]+=getEnergy()-myPrevEnergy?+delta;
}
myPrevEnergy?=getEnergy();

Changed: 67,68c64,66
if(favDistance==0d){ favDistance=e.getDistance(); }
double absBearing=e.getBearingRadians?()+getHeadingRadians(),distanceChangeAngle?,power=Math.min(e.getEnergy()/4,getEnergy()/10),x=getX(),y=getY(),latVel=Math.signum(getVelocity()*Math.sin(e.getBearingRadians?()));
dist=e.getDistance();
if(favDistance==0d){ favDistance=dist; }
double absBearing=e.getBearingRadians?()+getHeadingRadians(),vel=Math.signum(getVelocity()),turnAngle;

Added: 71a70
double diff=favDistance-dist;

Changed: 75,80c74,79
+(distanceChangeAngle?=(
(Math.abs(favDistance-e.getDistance())>tryAmt/2) ?
HALF_PI*
(Math.random()/2)*
latVel*
Math.signum(e.getDistance()-favDistance)
*((
(Math.abs(diff)>tryAmt/2) ?
1d+
Math.random()*
Math.signum(diff)*
vel

Changed: 82c81
0)))
1d)))

Changed: 84,94c83,91

int moveDir=(int)Math.signum(-latVel+0.000001);
while(!_fieldRect.contains(x+(Math.sin(turnAngle)*200*moveDir),y+(Math.cos(turnAngle)*200*moveDir))){
turnAngle=robocode.util.Utils.normalAbsoluteAngle?(turnAngle*(-moveDir*0.3 + 1));
//out.println(turnAngle);
//out.println((Math.signum(latVel+0.0001)*0.1 + 1));
}

// projectedPos.setLocation(x+(Math.sin(turnAngle)*200*moveDir),y+(Math.cos(turnAngle)*200*moveDir));

setTurnRightRadians?(robocode.util.Utils.normalRelativeAngle(turnAngle-getHeadingRadians()));
// tempX=x+Math.sin(absBearing)*dist;
// tempY=y+Math.cos(absBearing)*dist;
double stick=200d*vel;
for(int i=1;!_fieldRect.
contains(
getX() + stick*Math.sin(turnAngle+=Math.signum(vel*Math.sin(e.getBearingRadians?()))*i/500d),
getY() + stick*Math.cos(turnAngle)
) && i<500 && (((Math.abs(absBearing-turnAngle)<0.4 || i==499) ? move((int)(-getVelocity())):true)); i++);
setTurnRightRadians?(robocode.util.Utils.normalRelativeAngle(turnAngle-getHeadingRadians()));//out.println("Line 106");

Changed: 100,107c97
if(setFireBullet(power)!=null){
gain(-power);
}
}

public void onBulletHit?(BulletHitEvent? e){
double power=e.getBullet().getPower();
gain(power*3 + (power*4 + (2*Math.max(1,power-1))));
setFire(Math.min(e.getEnergy()/4,getEnergy()/10));

Removed: 109,114d98

public void onHitByBullet?(HitByBulletEvent? e){
double power=e.getPower();
gain(-(power*4 + (2*Math.max(1,power-1)) + power*3));
}


Changed: 116,118c100
double newVel=(Math.random()*40d)-20d;
setMaxVelocity?(Math.abs(newVel));
setAhead(newVel*Double.POSITIVE_INFINITY);
move(0);

Changed: 120,125c102,116
void gain(double energychange){
if(frontTried && !backTried){
energygain[0]+=energychange;
}else if(backTried){
energygain[1]+=energychange;
}
public boolean move(int dir){
double newVel=(Math.random()*41d) - 21d;
setMaxVelocity?(Math.abs(newVel)+1d);
setAhead(((dir==0) ? newVel:dir)*Double.POSITIVE_INFINITY);
return false;
}

/* public void onPaint(java.awt.Graphics2D g){
double distance=Point2D.Double.distance(tempX,tempY,getX(),getY());
g.drawOval((int)(tempX-distance),(int)(tempY-distance),(int)(distance*2),(int)(distance*2));
g.setColor(Color.GREEN);
g.drawOval((int)(tempX-favDistance),(int)(tempY-favDistance),(int)(favDistance*2),(int)(favDistance*2));
g.setColor(new Color(0,150,0));
g.drawOval((int)(tempX-favDistance-(tryAmt/2)),(int)(tempY-favDistance-(tryAmt/2)),(int)((tryAmt/2+favDistance)*2),(int)((tryAmt/2+favDistance)*2));
g.drawOval((int)(tempX-favDistance+(tryAmt/2)),(int)(tempY-favDistance+(tryAmt/2)),(int)((favDistance-(tryAmt/2))*2),(int)((favDistance-(tryAmt/2))*2));

Added: 126a118
*/

Removed: 128,131d119
// public void onPaint(java.awt.Graphics2D g){
// g.fillOval((int)projectedPos.getX(),(int)projectedPos.getY(),11,11);
// }


Added: 132a121


package ntc;
import robocode.*;
import java.awt.geom.*;
import java.awt.Color;

public class Plains extends AdvancedRobot
{	
	static private final double HALF_PI = Math.PI / 2;
	static private double lastEnergy,curEnergy,favDistance,tryAmt,myPrevEnergy,dist;
        static private final Rectangle2D.Double _fieldRect = new Rectangle2D.Double(18, 18, 724, 564);
	static private double[] energygain=new double[2];
	static private boolean tryingBack;
	static private int timeSinceLastChanged;
//	double tempX,tempY;
	
	public void run(){
		tryAmt=144d;
		timeSinceLastChanged=50;
		energygain=new double[2];
		tryingBack=false;
		setAdjustRadarForGunTurn(true);
		setAdjustGunForRobotTurn(true);
		setTurnRadarRight(Double.POSITIVE_INFINITY);
		while(true){			
			double delta=lastEnergy-curEnergy;
			
			if(delta<=3.01 && delta>=0.09){										
				move(0);
			}
			if(--timeSinceLastChanged<=0){
				if(!tryingBack){
					favDistance=Math.min(favDistance+=tryAmt*2d,575d);
					tryingBack=true;
//					out.println("Trying distance " + favDistance);
				}else{
					favDistance=Math.max(favDistance-=tryAmt*2.5,200d);
//					backTried=true;
//					out.println("Trying distance " + favDistance);
//					out.print("Best distance is ");
					if(energygain[1]>=energygain[0]){
						favDistance+=tryAmt*2d;
					}
//						out.println(favDistance + " since energygain[0] (" + ((int)energygain[0]) + ") > energygain[1] (" + ((int)energygain[1]) + ")");
//					else{
//						out.println(favDistance + " since energygain[1] (" + ((int)energygain[1]) + ") > energygain[0] (" + ((int)energygain[0]) + ")");
//					}
					energygain[0]=energygain[1]=0;
					tryAmt/=2;
					tryingBack=false;
					timeSinceLastChanged=120;
				}
				timeSinceLastChanged=Math.max(100,(int)tryAmt*2);
			}
			if(Math.abs(dist-favDistance)<=tryAmt/2){
				energygain[(tryingBack)?1:0]+=getEnergy()-myPrevEnergy+delta;
			}
			myPrevEnergy=getEnergy();			
			execute();
		}
	}

	public void onScannedRobot(ScannedRobotEvent e){
		dist=e.getDistance();
		if(favDistance==0d){ favDistance=dist; }
		double absBearing=e.getBearingRadians()+getHeadingRadians(),vel=Math.signum(getVelocity()),turnAngle;
		setTurnRadarLeft(getRadarTurnRemaining());
		lastEnergy=curEnergy;
		curEnergy=e.getEnergy();
		double diff=favDistance-dist;
		turnAngle=robocode.util.Utils.normalAbsoluteAngle(
							absBearing
							+HALF_PI
							*((
								(Math.abs(diff)>tryAmt/2) ? 
								1d+
								Math.random()*
								Math.signum(diff)*
								vel
								:
								1d)))
							;
//		tempX=x+Math.sin(absBearing)*dist;
//		tempY=y+Math.cos(absBearing)*dist;
		double stick=200d*vel;
		for(int i=1;!_fieldRect.
		contains(
				getX() + stick*Math.sin(turnAngle+=Math.signum(vel*Math.sin(e.getBearingRadians()))*i/500d),
				getY() + stick*Math.cos(turnAngle)
				) && i<500 && (((Math.abs(absBearing-turnAngle)<0.4 || i==499) ? move((int)(-getVelocity())):true)); i++);							
		setTurnRightRadians(robocode.util.Utils.normalRelativeAngle(turnAngle-getHeadingRadians()));//out.println("Line 106");
							
		setTurnGunRightRadians(
								robocode.util.Utils.normalRelativeAngle(
								absBearing-getGunHeadingRadians()
								));
		setFire(Math.min(e.getEnergy()/4,getEnergy()/10));
	}
	public void onHitRobot(HitRobotEvent e){
		move(0);
	}
	public boolean move(int dir){
		double newVel=(Math.random()*41d) - 21d;
		setMaxVelocity(Math.abs(newVel)+1d);
		setAhead(((dir==0) ? newVel:dir)*Double.POSITIVE_INFINITY);
		return false;
	}

/*	public void onPaint(java.awt.Graphics2D g){
		double distance=Point2D.Double.distance(tempX,tempY,getX(),getY());
		g.drawOval((int)(tempX-distance),(int)(tempY-distance),(int)(distance*2),(int)(distance*2));
		g.setColor(Color.GREEN);
		g.drawOval((int)(tempX-favDistance),(int)(tempY-favDistance),(int)(favDistance*2),(int)(favDistance*2));
		g.setColor(new Color(0,150,0));
		g.drawOval((int)(tempX-favDistance-(tryAmt/2)),(int)(tempY-favDistance-(tryAmt/2)),(int)((tryAmt/2+favDistance)*2),(int)((tryAmt/2+favDistance)*2));
		g.drawOval((int)(tempX-favDistance+(tryAmt/2)),(int)(tempY-favDistance+(tryAmt/2)),(int)((favDistance-(tryAmt/2))*2),(int)((favDistance-(tryAmt/2))*2));
	}
*/	

}


Robo Home | Plains | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited May 24, 2008 22:39 EST by Starrynte (diff)
Search: