cool codesize 219! |
cool codesize 219!--mike yeah,with the help of mike, codesize is now 219 w/ same functionality. --andrew |
package ahf; import robocode.*; import java.awt.geom.Rectangle2D; import robocode.util.Utils; public class Acero extends AdvancedRobot { static double direction; public void run(){ direction=1; setAdjustRadarForGunTurn(true); do{ turnRadarRightRadians(1); } while(true); } public void onScannedRobot(ScannedRobotEvent e){ double enemyAbsoluteBearing; double distance; double goalDirection =(enemyAbsoluteBearing=e.getBearingRadians()+getHeadingRadians())-(Math.PI/2+((distance=e.getDistance())>=600?0:0.4 ))*direction; while (!new Rectangle2D.Double(19.0,19.0,762.0,562.0).contains(getX()+Math.sin(goalDirection)*120,getY()+Math.cos(goalDirection)*120)){ goalDirection = goalDirection+direction*.1; if (Math.random()<.01) direction=-direction; } goalDirection = Utils.normalRelativeAngle(goalDirection-getHeadingRadians()); setTurnRightRadians(Math.tan(goalDirection)); setAhead(100*(Math.abs(goalDirection) > Math.PI/2 ?-1:1)); if (Math.random()<.04) direction=-direction; setTurnGunRightRadians(Utils.normalRelativeAngle(enemyAbsoluteBearing-getGunHeadingRadians())); setFire(2); setTurnRadarRightRadians(Utils.normalRelativeAngle(enemyAbsoluteBearing - getRadarHeadingRadians()) ); } }can anyone make it smaller?
oh yeah,in the next version i'll take out the distance variable or do somthing better than math.random<.04:direction*=-1 --andrew
You could replace your radar code and get some space. Take a look to any of the open source nanos (ie. NanoLauLectrik) to see the implementation. It avoids the do-while loop in the run method and makes the setTurnRadar?... simpler. -- Albert
isn't this the best radar configuration there is for nanos? the do while loop is the same as the turnrightradians(infiniti) thing in terms of bytes. and the loop is better because when it falls off, it doesn't just die.
I haven't measured the exact number of bytes used, but
public void run() { turnRadarRightRadians?(Double.POSITIVE_INFINITY); } public void onScannedRobot(ScannedRobotEvent e) { setTurnRadarLeftRadians(getRadarTurnRemaining?()); }will probably be smaller (anyway, it's worth a try). In the other hand, it never stops when it falls, because the remaining turn of infinity is just infinity :-) Albert
thanks Albert, i'll try it. --andrew
Changing your while loop to a do-while loop will make it slightly smaller, too, if you think it's ok to do. -- Kawigi
don't i have a do-while loop?--andrew
he means the while loop in your "onScannedRobot" handler... --Brainfade
ah. thanks, i'll try it. --andrew
anyone know what the most effective gun would be. i can have about 15 more bytes while having head on. --andrew
cool codesize 219!--mike
yeah,with the help of mike, codesize is now 219 w/ same functionality. --andrew