Difference between revisions of "GITS/Targeting/Source"

From Robowiki
Jump to navigation Jump to search
(New page: '''GITS Targeting (Source)''' - from version 0.5-051409 ---- <pre> public void onScannedRobot(ScannedRobotEvent e) { double rSweep = 0.99; //RadarSweep tweak double bPower = Math.min(3.0...)
 
(removing source code category since this currently doesn't have any source code)
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
'''GITS Targeting (Source)''' - from version 0.5-051409
+
'''GITS Targeting (Source)''' - from version 0.5-051509
 
----
 
----
<pre>
+
I took down the source because I'm going to rewrite the GhostGun using classes to extend the plug-ability. I will post that when I get a (most likely horrible) working version.
public void onScannedRobot(ScannedRobotEvent e) {
 
double rSweep = 0.99; //RadarSweep tweak
 
double bPower = Math.min(3.0,getEnergy());
 
double myX = getX();
 
double myY = getY();
 
double aBearing = (getHeadingRadians() + e.getBearingRadians());
 
double hisX = (getX() + e.getDistance() * Math.sin(aBearing));
 
double hisY = (getY() + e.getDistance() * Math.cos(aBearing));
 
double eHeading = e.getHeadingRadians();
 
double eVelocity = e.getVelocity();
 
double eDistance = e.getDistance();
 
double eEnergy = e.getEnergy();
 
double dTime = 0;
 
double fHeight = getBattleFieldHeight(),
 
  fWidth = getBattleFieldWidth();
 
double aHisX = hisX, aHisY = hisY;
 
 
while((++dTime) * (20.0 - 3.0 * bPower) < Point2D.Double.distance(myX, myY, aHisX, aHisY)) {
 
aHisX += (Math.sin(eHeading) * eVelocity);
 
aHisY += (Math.cos(eHeading) * eVelocity);
 
if(aHisX < 18.0 || aHisX > (fWidth - 18.0) || aHisY < 18.0 || aHisY > (fHeight - 18.0)) {
 
aHisX = Math.min(Math.max(18.0, aHisX), (fWidth - 18.0));
 
aHisY = Math.min(Math.max(18.0, aHisY), (fHeight - 18.0));
 
break;
 
}
 
}
 
double theta = Utils.normalAbsoluteAngle(Math.atan2((aHisX - getX()), (aHisY - getY())));
 
 
//Set and Execute Things
 
setTurnGunRightRadians(Utils.normalRelativeAngle(theta - getGunHeadingRadians()));
 
setTurnRadarRightRadians((rSweep)*Utils.normalRelativeAngle(aBearing - getRadarHeadingRadians()));
 
execute();
 
 
if(eEnergy >= (0.025 * eDistance)) { fire(bPower); } //PowerConserve tweak
 
}
 
</pre>
 
----
 
Currently, this targeting formula works for simple robots 90% of the time. It's rubbish against most advanced robots. Feel free to improve/comment on it so I can learn (since tutorials are utterly useless on me, I need visual aids).
 

Latest revision as of 10:48, 9 May 2010

GITS Targeting (Source) - from version 0.5-051509


I took down the source because I'm going to rewrite the GhostGun using classes to extend the plug-ability. I will post that when I get a (most likely horrible) working version.