[Home]N/source

Robo Home | N | Changes | Preferences | AllPages

package baal.nano;
import robocode.*;
import robocode.util.Utils;

// N 1.4
// 247 bytes.

public class N extends AdvancedRobot
{
	static final double infinity = Double.POSITIVE_INFINITY;
	static double move = 45;
			
	public void run() {
		setAdjustGunForRobotTurn(true);
		turnRadarRightRadians(infinity);
	}
	public void onScannedRobot(ScannedRobotEvent e) {
		double absoluteBearing = getHeadingRadians() + e.getBearingRadians();
		if (Math.random() < 0.07 || getGunHeat() <= 0.1)
			move = -move;
		setTurnRadarLeftRadians(getRadarTurnRemaining());
		setTurnGunRightRadians(Utils.normalRelativeAngle(absoluteBearing - getGunHeadingRadians() + 
			(e.getVelocity() * Math.sin(e.getHeadingRadians() - absoluteBearing) / 13.0)));
		if(e.getEnergy() >= 15.0 || getEnergy() - e.getEnergy() <= 7.0) {
			setAhead(((getGunHeat()*100)*Math.random())*move);
			setTurnRight(e.getBearing() + 80.0);
			fire(2.5 - Math.max(0, (30 - getEnergy()) / 16));
		}
		else if(getEnergy() - e.getEnergy() >= 7.0){
			setTurnRight(e.getBearing());	
			setAhead(infinity);
			fire(1.0);
		}
	}
	public void onHitWall(HitWallEvent e) {
		setAhead(move = -move * 10 * Math.random());
	}
}


Comments / Feedback

Can anyone hint at why my movement brings the suckage? Baal

Try using setTurnLeftRadians(Math.cos(absoluteBearing)) (I'm assuming you want to always move perpendicular to the enemy?). Also, take the Math.cos() out of the setAhead method. -- Simonton

I really don't care about my position relative to the enemy, I just want to dodge bullets :-) -- Baal

In general, your best bet is to stay perpendicular then ;) -- Voidious

I'm testing it now with

setAhead(MoveLength * Math.random() * 2 * Direction);
setTurnLeftRadians(Math.cos(absoluteBearing));
and the movement is weird, i'm assuming that increasing movelength will increase distance away, correct? -- Baal

Changing moveLength will not change your distance to the enemy. To do that you must turn your bot such that it angles slightly away/toward the enemy (and be careful, because this this adjustment to the angle will be opposite depending on whether you are travelling backward or forward). MoveLength? currently will change how far your robot tries to travel between each tick. That is, it will change its speed. Note that calling setAhead(20) or greater each tick will move your bot at full speed. -- Simonton

ok, got the perpindicular movement working, and I'm getting a 50% increase in scores in my tests. Updating rumble version -- Baal

Looks like N scores 130 points better in ranking, meaning you rank 50 places up. Congrats with this nice improvement, but I expect to see more jumps like this from you. -- GrubbmGait

Thanks, I'm messing with some circular prediction code, but I'm seeing it causes some scores to drop from my HOT gun, I need to find a way to fit virtual guns in N :) -- Baal

Yep, against oscillators a circular or linear gun is hopeless. On the other hand, a reasonable circular gun alone would improve your score in the rumble considerably, meaning from 1400 to (close to) 1500. A virtual gun array is only beneficial if each gun itself can hit what it is supposed to hit. -- GrubbmGait

Yup, Version 0.5 had a linear gun, and changing it to Head On increased my rating in the nanorumble about 100 points. I'm hoping that a vguns array using a HOT gun and a circular prediction gun will get me a couple of ratings. Thinking about it, a vguns array would probably get me in the top 50 IF i can fit it in a nano, else, I'll just try to improve the movement, and maybe do a simple random gun. :-) Baal

A reasonable way to combine the ideas if you can't fit the VGs in is to use a weighted average of their velocity or something. -- Kawigi

Hadn't thought of that... -- Baal

Looking at your suggestion again Kawigi, wouldn't that be somewhat like Mean Targeting? -- Baal

Well, I'm going to hold off updating N with any new stuff immediatly. I am instead going to focus on shrinking the code, which I know I get down from 240 -ish. -- Baal

In-lining the Move function should save you a few bytes (maybe 3?) -- Nfwu

Any ideas on where to spend my 30-something bytes of code I have left? I'm leaning towards Energy management, but can't seem to devise an efficient algorithm, any ideas -- Baal

I don't know the exact byte count off-hand, but this is the kind of code I use in Komarious: double power = 2 - Math.max(0, (30 - getEnergy()) / 16);. So I fire power=2 as long as I'm over 30 energy, and that scales down to around 0.2 bullet power at 1 energy; you could easily tweak it to whatever values you want, of course. -- Voidious

Thanks, void -- Baal

You can save some room by removing the else statement and placing the setTurnLeftRadians? from it before the if statement, as robocode always uses the last turn statement given. Also I think you can make Math.cos(e.getBearingRadians?()) * Math.PI/2 into a variable and that will save some space too.

Like so

setTurnLeftRadians(absoluteBearing = (Math.cos(e.getBearingRadians()) * Math.PI/2));
if(e.getDistance() > MoveLength) {
	setTurnLeftRadians(absoluteBearing - Direction);
}

--Chase-san

I'm not sure it will save any space at all, but you might change the radar to degrees, since N uses a infinity lock --Starrynte

I'm a bytesaver I guess, but I guess if you have colors you have enough to spare huh? Degrees is overrated IMHO. --Chase-san

1.25 is 219 as shown above, so I'm really not that pressed for space :P, Thats not to say your suggestions will go unheeded, just that I really don't need the space at the moment. :) -- Baal

After I allowed this page to die, I've performed CPR, and successfully ressucitated this page :P. Just a note: version 1.4 is 247 bytes as above. -- Baal


Robo Home | N | Changes | Preferences | AllPages
Edit text of this page | View other revisions
Last edited March 29, 2008 1:59 EST by Baal (diff)
Search: