Difference between revisions of "GITS/Targeting/Source"

From Robowiki
Jump to navigation Jump to search
(Updated Source)
(removing source code category since this currently doesn't have any source code)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
'''GITS Targeting (Source)''' - from version 0.5-051509
 
'''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 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 eAbsBearing = e.getBearingRadians() + getHeadingRadians(); //Enemy Absolute Bearing
 
double eHeading = e.getHeadingRadians();
 
double eHeadingChange = eHeading - _eHeading; //Heading data for later
 
_eHeading = eHeading; //Update the enemy heading
 
double eVelocity = e.getVelocity();
 
double eLatVel = eVelocity*Math.sin(eHeading - eAbsBearing); //Enemy Lateral Velocity
 
double eDistance = e.getDistance();
 
double eEnergy = e.getEnergy();
 
double dTime = 0;
 
double fHeight = getBattleFieldHeight(),
 
fWidth = getBattleFieldWidth();
 
double aHisX = hisX, aHisY = hisY;
 
int GBM = (eVelocity < 0 ? -1 : 1); //Going Backwards Multiplier
 
int MCV = 0; //Most Common Velocity
 
int eAbsVelocity = (int)Math.round(Math.abs(eVelocity));
 
_vCounts[eAbsVelocity]++;
 
int _MCV = _vCounts[0];
 
//A bunch of bullet calulations
 
double MBP = (eEnergy > 15.9 ? 3.0 : //If Enemy's Energy is at or over 16 points
 
(eEnergy > 7.9 ? 2.0 : //If Enemy's Energy is at or over 8 points
 
(eEnergy > 3.9 ? 1.0 : 0.5))); //Everything else, basically
 
double bPower = Math.min(MBP,getEnergy()); //Figure out the max you can spend on firing a bullet
 
double bVelocity = (20 - (3 * bPower));
 
//Historical Velocity Recall
 
for (int i = 1; i < 9; i++) {
 
if(_vCounts[i] > _MCV) {
 
_MCV = _vCounts[i];
 
MCV = i;
 
}
 
}
 
 
while((++dTime) * bVelocity < Point2D.Double.distance(myX, myY, aHisX, aHisY)) {
 
aHisX += (Math.sin(eHeading) * eVelocity);
 
aHisY += (Math.cos(eHeading) * eVelocity);
 
eHeading += eHeadingChange;
 
if(aHisX < 20.0 || aHisX > (fWidth - 20.0) || aHisY < 20.0 || aHisY > (fHeight - 20.0)) {
 
aHisX = Math.min(Math.max(20.0, aHisX), (fWidth - 20.0));
 
aHisY = Math.min(Math.max(20.0, aHisY), (fHeight - 20.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)) { setFire(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.