Difference between revisions of "Talk:Opposite"
Jump to navigation
Jump to search
m (added signature) |
(This might help) |
||
Line 1: | Line 1: | ||
Any ideas for a targeting scheme with 132 bytes? (including how to select a target) --[[User:Starrynte|Starrynte]] 17:45, 12 September 2009 (UTC) | Any ideas for a targeting scheme with 132 bytes? (including how to select a target) --[[User:Starrynte|Starrynte]] 17:45, 12 September 2009 (UTC) | ||
+ | |||
+ | I'm not sure how much this will help, but this is the enemy selection I tend to use in codesize-restricted melee bots. I used linear targeting in this example: | ||
+ | <pre>package oog.nano.aorta; | ||
+ | |||
+ | import robocode.*; | ||
+ | import robocode.util.*; | ||
+ | |||
+ | public class Aorta extends AdvancedRobot { | ||
+ | static double enemyDist; | ||
+ | static String enemyName; | ||
+ | public void run(){ | ||
+ | enemyDist=Double.POSITIVE_INFINITY; | ||
+ | setTurnRadarRightRadians(Double.POSITIVE_INFINITY); | ||
+ | } | ||
+ | public void onScannedRobot(ScannedRobotEvent e){ | ||
+ | if(e.getDistance()<enemyDist||e.getName()==enemyName){ | ||
+ | enemyName=e.getName(); | ||
+ | enemyDist=e.getDistance(); | ||
+ | |||
+ | //This part greatly increases the accuracy of the targeting, but it isn't necessary. | ||
+ | if(getGunHeat()<1){ | ||
+ | setTurnRadarLeftRadians(getRadarTurnRemainingRadians()); | ||
+ | } | ||
+ | |||
+ | /* | ||
+ | *You could replace these next two lines with any type of targeting and bullet power you like, | ||
+ | *I just used linear targeting as an example. | ||
+ | */ | ||
+ | setTurnGunRightRadians(Utils.normalRelativeAngle((e.getBearingRadians()+getHeadingRadians())-getGunHeadingRadians())+ | ||
+ | (e.getVelocity()*Math.sin(e.getHeadingRadians()-(e.getBearingRadians()+getHeadingRadians())))/14); | ||
+ | setFire(2); | ||
+ | } | ||
+ | } | ||
+ | public void onRobotDeath(RobotDeathEvent e){ | ||
+ | enemyDist=Double.POSITIVE_INFINITY; | ||
+ | } | ||
+ | } | ||
+ | </pre> |
Revision as of 19:03, 12 September 2009
Any ideas for a targeting scheme with 132 bytes? (including how to select a target) --Starrynte 17:45, 12 September 2009 (UTC)
I'm not sure how much this will help, but this is the enemy selection I tend to use in codesize-restricted melee bots. I used linear targeting in this example:
package oog.nano.aorta; import robocode.*; import robocode.util.*; public class Aorta extends AdvancedRobot { static double enemyDist; static String enemyName; public void run(){ enemyDist=Double.POSITIVE_INFINITY; setTurnRadarRightRadians(Double.POSITIVE_INFINITY); } public void onScannedRobot(ScannedRobotEvent e){ if(e.getDistance()<enemyDist||e.getName()==enemyName){ enemyName=e.getName(); enemyDist=e.getDistance(); //This part greatly increases the accuracy of the targeting, but it isn't necessary. if(getGunHeat()<1){ setTurnRadarLeftRadians(getRadarTurnRemainingRadians()); } /* *You could replace these next two lines with any type of targeting and bullet power you like, *I just used linear targeting as an example. */ setTurnGunRightRadians(Utils.normalRelativeAngle((e.getBearingRadians()+getHeadingRadians())-getGunHeadingRadians())+ (e.getVelocity()*Math.sin(e.getHeadingRadians()-(e.getBearingRadians()+getHeadingRadians())))/14); setFire(2); } } public void onRobotDeath(RobotDeathEvent e){ enemyDist=Double.POSITIVE_INFINITY; } }