<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://robowiki.net/w/index.php?action=history&amp;feed=atom&amp;title=User%3AChase-san%2FBasicTracker</id>
	<title>User:Chase-san/BasicTracker - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://robowiki.net/w/index.php?action=history&amp;feed=atom&amp;title=User%3AChase-san%2FBasicTracker"/>
	<link rel="alternate" type="text/html" href="http://robowiki.net/w/index.php?title=User:Chase-san/BasicTracker&amp;action=history"/>
	<updated>2026-04-18T10:03:27Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.1</generator>
	<entry>
		<id>http://robowiki.net/w/index.php?title=User:Chase-san/BasicTracker&amp;diff=23037&amp;oldid=prev</id>
		<title>Chase-san at 18:57, 30 November 2011</title>
		<link rel="alternate" type="text/html" href="http://robowiki.net/w/index.php?title=User:Chase-san/BasicTracker&amp;diff=23037&amp;oldid=prev"/>
		<updated>2011-11-30T18:57:49Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 18:57, 30 November 2011&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l28&quot; &gt;Line 28:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 28:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  */&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  */&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;public class BasicTracker {&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;public class BasicTracker {&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;	//not always correct, use at your own risk&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;	&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;private boolean enemyIsNormalRobot = false; &lt;/ins&gt;//not always correct, use at your own risk&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;	private boolean enemyIsNormalRobot = false;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;	public Point2D enemyPosition = new Point2D.Double();&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;	public Point2D enemyPosition = new Point2D.Double();&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;	public double enemyEnergy = 100;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;	public double enemyEnergy = 100;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Chase-san</name></author>
		
	</entry>
	<entry>
		<id>http://robowiki.net/w/index.php?title=User:Chase-san/BasicTracker&amp;diff=23035&amp;oldid=prev</id>
		<title>Chase-san: whoops</title>
		<link rel="alternate" type="text/html" href="http://robowiki.net/w/index.php?title=User:Chase-san/BasicTracker&amp;diff=23035&amp;oldid=prev"/>
		<updated>2011-11-30T02:31:29Z</updated>

		<summary type="html">&lt;p&gt;whoops&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 02:31, 30 November 2011&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l2&quot; &gt;Line 2:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 2:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;It is only for one on one at the moment. The melee version is obviously much more complex, and relies a great deal on the radar.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;It is only for one on one at the moment. The melee version is obviously much more complex, and relies a great deal on the radar.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;syntaxhighligh&lt;/del&gt;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;syntaxhighlight&lt;/ins&gt;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;//'naive' is used to keep versions of my custom classes&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;//'naive' is used to keep versions of my custom classes&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;//that do not extensively use internal code structures&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;//that do not extensively use internal code structures&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Chase-san</name></author>
		
	</entry>
	<entry>
		<id>http://robowiki.net/w/index.php?title=User:Chase-san/BasicTracker&amp;diff=23033&amp;oldid=prev</id>
		<title>Chase-san: Accurate Energy Tracking (wall/robot collision) 1 on 1</title>
		<link rel="alternate" type="text/html" href="http://robowiki.net/w/index.php?title=User:Chase-san/BasicTracker&amp;diff=23033&amp;oldid=prev"/>
		<updated>2011-11-30T02:26:49Z</updated>

		<summary type="html">&lt;p&gt;Accurate Energy Tracking (wall/robot collision) 1 on 1&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;A basic tracker that accurately tracks enemy energy drop information. This also requires it to track a whole bunch of other stuff (at least for the wall collision).&lt;br /&gt;
It is only for one on one at the moment. The melee version is obviously much more complex, and relies a great deal on the radar.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighligh&amp;gt;&lt;br /&gt;
//'naive' is used to keep versions of my custom classes&lt;br /&gt;
//that do not extensively use internal code structures&lt;br /&gt;
package cs.naive;&lt;br /&gt;
&lt;br /&gt;
import java.awt.geom.Point2D;&lt;br /&gt;
import java.awt.geom.Rectangle2D;&lt;br /&gt;
&lt;br /&gt;
import robocode.BulletHitEvent;&lt;br /&gt;
import robocode.HitByBulletEvent;&lt;br /&gt;
import robocode.HitRobotEvent;&lt;br /&gt;
import robocode.RobotStatus;&lt;br /&gt;
import robocode.Rules;&lt;br /&gt;
import robocode.ScannedRobotEvent;&lt;br /&gt;
import robocode.StatusEvent;&lt;br /&gt;
&lt;br /&gt;
import static java.lang.Math.*;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Tracks some basic changes in an enemy.&lt;br /&gt;
 * Mainly everything in here is enough to precisely track enemy energy drop.&lt;br /&gt;
 * It is a handful, so I decided to separate it out.&lt;br /&gt;
 * &lt;br /&gt;
 * @author Chase&lt;br /&gt;
 */&lt;br /&gt;
public class BasicTracker {&lt;br /&gt;
	//not always correct, use at your own risk&lt;br /&gt;
	private boolean enemyIsNormalRobot = false;&lt;br /&gt;
	public Point2D enemyPosition = new Point2D.Double();&lt;br /&gt;
	public double enemyEnergy = 100;&lt;br /&gt;
	public double enemyEnergyDelta = 0;&lt;br /&gt;
	public double enemyVelocity = 0;&lt;br /&gt;
	public double enemyVelocityDelta = 0;&lt;br /&gt;
	public double enemyHeading = 0;&lt;br /&gt;
	public double enemyHeadingDelta = 0;&lt;br /&gt;
	public final Rectangle2D battlefield;&lt;br /&gt;
&lt;br /&gt;
	public BasicTracker(double fieldWidth, double fieldHeight) {&lt;br /&gt;
		battlefield = new Rectangle2D.Double(18,18,fieldWidth-36,fieldHeight-36);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	public Point2D myPosition = new Point2D.Double();&lt;br /&gt;
	public double myHeading = 0;&lt;br /&gt;
	&lt;br /&gt;
	public void onStatus(StatusEvent e) {&lt;br /&gt;
		RobotStatus status = e.getStatus();&lt;br /&gt;
		myPosition = new Point2D.Double(status.getX(),status.getY());&lt;br /&gt;
		myHeading = status.getHeadingRadians();&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	public void onScannedRobot(ScannedRobotEvent e) {&lt;br /&gt;
		double angleToEnemy = e.getBearingRadians() + myHeading;&lt;br /&gt;
		&lt;br /&gt;
		double newEnemyEnergy = e.getEnergy();&lt;br /&gt;
		double newEnemyVelocity = e.getVelocity();&lt;br /&gt;
		double newEnemyHeading = e.getHeadingRadians();&lt;br /&gt;
		double newEnemyVelocityDelta = newEnemyVelocity - enemyVelocity;&lt;br /&gt;
		double newEnemyHeadingDelta = newEnemyHeading - enemyHeading;&lt;br /&gt;
		Point2D newEnemyPosition = project(myPosition, angleToEnemy, e.getDistance());&lt;br /&gt;
		&lt;br /&gt;
		/*&lt;br /&gt;
		 * Enemy wall collision correction.&lt;br /&gt;
		 * This is the part that requires so much more information to handle.&lt;br /&gt;
		 */&lt;br /&gt;
		if(abs(newEnemyVelocity) == 0.0 &amp;amp;&amp;amp; !enemyIsNormalRobot) {&lt;br /&gt;
			double fullSpeed = limit(-Rules.MAX_VELOCITY,&lt;br /&gt;
					enemyVelocity + enemyVelocityDelta,&lt;br /&gt;
					Rules.MAX_VELOCITY);&lt;br /&gt;
			/*&lt;br /&gt;
			 * Can we determine if they decided to slow down&lt;br /&gt;
			 * the very exact instant before they hit the wall?&lt;br /&gt;
			 * No, but if they did hit the wall (as is likely here),&lt;br /&gt;
			 * then it is unlikely they suddenly changed their mind&lt;br /&gt;
			 * so shortly before collision.&lt;br /&gt;
			 */&lt;br /&gt;
			Point2D target = project(enemyPosition, enemyHeading, fullSpeed);&lt;br /&gt;
&lt;br /&gt;
			if(!battlefield.contains(target)) {&lt;br /&gt;
				double wallDamage = Rules.getWallHitDamage(abs(fullSpeed));&lt;br /&gt;
&lt;br /&gt;
				if(wallDamage == 0 || enemyEnergy == newEnemyEnergy) {&lt;br /&gt;
					if(wallDamage &amp;gt; 0.2)&lt;br /&gt;
						enemyIsNormalRobot = true;&lt;br /&gt;
				} else {&lt;br /&gt;
					/*&lt;br /&gt;
					 * Detected wall collision&lt;br /&gt;
					 */&lt;br /&gt;
					enemyEnergy -= wallDamage;&lt;br /&gt;
				}&lt;br /&gt;
			}&lt;br /&gt;
		}&lt;br /&gt;
		&lt;br /&gt;
		enemyEnergyDelta = enemyEnergy - newEnemyEnergy;&lt;br /&gt;
		&lt;br /&gt;
		/*&lt;br /&gt;
		 * Reset the energy to track&lt;br /&gt;
		 */&lt;br /&gt;
		enemyEnergy = newEnemyEnergy;&lt;br /&gt;
		enemyVelocity = newEnemyVelocity;&lt;br /&gt;
		enemyHeading = newEnemyHeading;&lt;br /&gt;
		enemyVelocityDelta = newEnemyVelocityDelta;&lt;br /&gt;
		enemyHeadingDelta = newEnemyHeadingDelta;&lt;br /&gt;
		enemyPosition = newEnemyPosition;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	public void onBulletHit(BulletHitEvent e) {&lt;br /&gt;
		/* &lt;br /&gt;
		 * Determine how much damage our bullet does to the enemy&lt;br /&gt;
		 * and adjust our stored copy to reflect the amount lost&lt;br /&gt;
		 */&lt;br /&gt;
		enemyEnergy -= Rules.getBulletDamage(e.getBullet().getPower());&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	public void onHitByBullet(HitByBulletEvent e) {&lt;br /&gt;
		/*&lt;br /&gt;
		 * Increase the enemy energy based on how powerful the bullet that&lt;br /&gt;
		 * hit us was this is so we can get reliable energy drop detection&lt;br /&gt;
		 */&lt;br /&gt;
		enemyEnergy += Rules.getBulletHitBonus(e.getPower());&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	private long lastRobotHitTime = 0;&lt;br /&gt;
	public void onHitRobot(HitRobotEvent e) {&lt;br /&gt;
		long time = e.getTime();&lt;br /&gt;
		/*&lt;br /&gt;
		 * Correct enemy energy based on robot collision&lt;br /&gt;
		 */&lt;br /&gt;
		if(time != lastRobotHitTime) {&lt;br /&gt;
			lastRobotHitTime = time;&lt;br /&gt;
			enemyEnergy -= 0.6;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	public static final double limit(double min, double value, double max) {&lt;br /&gt;
		if (value &amp;gt; max) return max;&lt;br /&gt;
		if (value &amp;lt; min) return min;&lt;br /&gt;
		return value;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	public static final Point2D project(Point2D p, double angle, double distance) {&lt;br /&gt;
		return new Point2D.Double(p.getX() + sin(angle) * distance, p.getY() + cos(angle) * distance);&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Chase-san</name></author>
		
	</entry>
</feed>