Difference between revisions of "Spitfire"

From Robowiki
Jump to navigation Jump to search
m (→‎Version 1.1: add another version 1.1 note)
m (→‎Example Code: updated code examples to v1.1)
Line 23: Line 23:
 
protected void addComponents(ComponentChain componentChain) {
 
protected void addComponents(ComponentChain componentChain) {
 
componentChain.addDefaultComponents(new BasicRadar(45, 3));
 
componentChain.addDefaultComponents(new BasicRadar(45, 3));
BulletShieldingFactory.addBulletShieldingComponentsAlwaysApplies(componentChain, 0.1d);
+
BulletShieldingFactory.addBulletShieldingComponentsAsDefault(componentChain, 0.1d);
 
}
 
}
 
}
 
}
Line 33: Line 33:
  
 
<pre>
 
<pre>
public static void addBulletShieldingComponentsAlwaysApplies(ComponentChain chain, double maxAdjustedFirePower) {
+
public static void addBulletShieldingComponentsAsDefault(ComponentChain chain, double maxAdjustedFirePower) {
 
BulletShieldingDrive bulletShieldingDrive = new BulletShieldingDrive();
 
BulletShieldingDrive bulletShieldingDrive = new BulletShieldingDrive();
 
BulletShieldingController bulletShieldingController  
 
BulletShieldingController bulletShieldingController  
= new BulletShieldingController(bulletShieldingDrive, 7);
+
= new BulletShieldingController(bulletShieldingDrive);
 
BulletShieldingGun bulletShieldingGun = null;
 
BulletShieldingGun bulletShieldingGun = null;
 
if (maxAdjustedFirePower < RCPhysics.MIN_FIRE_POWER) {
 
if (maxAdjustedFirePower < RCPhysics.MIN_FIRE_POWER) {
Line 43: Line 43:
 
bulletShieldingGun = new BulletShieldingGun(bulletShieldingController, maxAdjustedFirePower);
 
bulletShieldingGun = new BulletShieldingGun(bulletShieldingController, maxAdjustedFirePower);
 
}
 
}
Scenario bulletShieldingScenario = new Scenario() {
+
chain.addDefaultComponents(bulletShieldingDrive, bulletShieldingGun);
@Override
 
public boolean applies() {
 
return true;
 
}
 
};
 
chain.addComponents(bulletShieldingScenario, bulletShieldingDrive, bulletShieldingGun);
 
 
}
 
}
 
</pre>
 
</pre>
Line 56: Line 50:
  
 
For v1.0, I'm not utilizing the max adjusted fire power functionality.  I just always use 0.1 shots.  If I ever turn it on, it will vary the fire power up to the given amount in an attempt to improve the shielding overlap.
 
For v1.0, I'm not utilizing the max adjusted fire power functionality.  I just always use 0.1 shots.  If I ever turn it on, it will vary the fire power up to the given amount in an attempt to improve the shielding overlap.
 
The parameter 7 sent to the controller is the number of ticks needed to prep for and shield an opponent shot.  This is higher than I'd like, and I hope to make some improvements in the future to reduce that number.
 

Revision as of 16:14, 21 February 2013

Spitfire is a robot that only uses bullet shielding. It provides an interesting point of reference for the technique, and also serves as a base for the bullet shielding mode in my robot XanderCat. It is based on my Xander Framework.

Version Notes

Version 1.1

  • Improve how lead time required for successful shielding is calculated. This improves shielding against close fighting opponents.
  • Fix bug that was causing Spitfire to not shoot against some opponents.

Example Code

The main robot class; short and sweet:

public class Spitfire extends AbstractXanderRobot {

	@Override
	protected void configure(Configuration configuration) {
		configuration.setAutoFireOnDisabledOpponents(false);
	}

	@Override
	protected void addComponents(ComponentChain componentChain) {
		componentChain.addDefaultComponents(new BasicRadar(45, 3));
		BulletShieldingFactory.addBulletShieldingComponentsAsDefault(componentChain, 0.1d);	
	}
}

Above, the call setAutoFireOnDisabledOpponents seems a little backwards, as Spitfire does fire on disabled opponents. The Xander Framework auto-fire functionality (which this setting turns on and off) is set up to fire a head-on shot immediately on a disabled opponent. However, with Spitfire, it needs to be sure that all opponent shots have been shielded before firing on a disabled opponent. For now, I just handle this in the bullet shielding gun. In the future, I may update the framework to make this a little more configurable to handle either approach.

Below, a look at the BulletShieldingFactory method for setting up the bullet shielding components:

public static void addBulletShieldingComponentsAsDefault(ComponentChain chain, double maxAdjustedFirePower) {
	BulletShieldingDrive bulletShieldingDrive = new BulletShieldingDrive();
	BulletShieldingController bulletShieldingController 
		= new BulletShieldingController(bulletShieldingDrive);
	BulletShieldingGun bulletShieldingGun = null;
	if (maxAdjustedFirePower < RCPhysics.MIN_FIRE_POWER) {
		bulletShieldingGun = new BulletShieldingGun(bulletShieldingController);
	} else {
		bulletShieldingGun = new BulletShieldingGun(bulletShieldingController, maxAdjustedFirePower);
	}
	chain.addDefaultComponents(bulletShieldingDrive, bulletShieldingGun);		
}

My current design uses a "controller" to deal with tracking shots, and it serves as an intermediary between the drive and gun. The gun requests waves from the controller, and the controller tells the drive what to do and lets the gun know when it's okay to fire.

For v1.0, I'm not utilizing the max adjusted fire power functionality. I just always use 0.1 shots. If I ever turn it on, it will vary the fire power up to the given amount in an attempt to improve the shielding overlap.