User:Nat/TargetingProblem
Can anyone answer my question?
I've some targeting system that I create it accidentally and it work well (for those nanobot):
double absBearing, vel;
// find average velocity
avgVelocity = (avgVelocity + Math.abs(vel = e.getVelocity())) / 2; // the avgVelocity is preloaded as 4
// Targeting
setTurnGunRightRadians(robocode.util.Utils.normalRelativeAngle(
(e.getBearingRadians() + getHeadingRadians()) +
Math.asin(
// This is a magical line! at first it look like this:
// Math.sin(e.getDistance()) * vel
// but for hit StopNGo movement, I must assume a magic velocity in order to
// hit it. I also need an average velocity in order to hit SittingDuck!
Math.sin(e.getDistance()) * ((avgVelocity < 0.00001 || vel > 0.5) ? vel : 4.5 * ((vel > 0) ? 1 : -1))
/ (20 - 3 * 2)
)
- getGunHeadingRadians()
));
// 2 is cheaper than 1.9!
setFire(2D);
That code copy almost exactly from one of my robot using it (not yet released). Can anyone answer me how this gun hit so much, or it just one kind of RandomTargeting?
Note: I don't have answer, this is not a joke!
Note: Please answer on this page, not a discussion page!
Well, having Math.sin(e.getDistance())
is a huge randomizer, so I'd definitely call this a form of random targeting. As I'm understanding the code, it seems like avgVelocity < 0.00001
will only be true if the enemy doesn't move for a while, and in that case vel = 0, so you'll be shooting head-on. Other than that special case, it looks like you're shooting at a random angle between Math.asin(4.5 / bullet speed) and its inverse; I don't think you'll ever hit a bot that just orbits you without ever stopping, though, because the max escape angle is Math.asin(8 / bullet speed). But I'm just giving this a quick look right now, sorry if I misunderstood something. --Voidious 17:35, 14 January 2009 (UTC)
No, the ((avgVelocity < 0.00001 || vel > 0.5) ? vel : 4.5 * ((vel > 0) ? 1 : -1))
is for hit the StopNGo movement, where the fire time its velocity is zero and it end up firing head-on so vel > 0.5
check that it's moving or not, and avgVelocity < 0.00001
check is enemy SittingDuck or not :)
Well, I know that trig function are randomizer, but if distance and velocity are same then the firing angle is the same, too. I think I'd call it semi-random targeting.
Thank you for your answer,Voidious --Nat 12:16, 15 January 2009 (UTC)