Well just something I started while waiting for results on PulsarMax really, first it was to test some of my very fundemental movement things in PulsarMax, but I couldn't resist to add guns etc. Let me tell you, 250 codesize is restricting!! Had to scratch most of my ideas at once! My hope now is to learn something more about the basics of Robocode and fighting simple bots. So no real contender, though I might make a melee version too with a few simple changes -- Pulsar
This Nano-bot thing was addicting and a very good distraction when waiting for PulsarMax TC runs etc to complete, so due to PulsarMax being a slow bot this bot came to be :). Version 0.1.5 looks very promising I must say. -- Pulsar
Wow, nanos are a lot of fun, so quick to test too :) This has actually slightly delayed some improvements for PulsarMax at times now. -- Pulsar
package pulsar; import robocode.AdvancedRobot; import robocode.HitByBulletEvent; import robocode.HitWallEvent; import robocode.ScannedRobotEvent; import robocode.util.Utils; /** * * @author Mattias Bergander (Pulsar) */ public class PulsarNano extends AdvancedRobot { static double distance, bulletVelocity; static int direction = 1; static int moveTimer, movingForwardHits; static long lastDirectionChange; public void run() { turnRadarRight(Double.POSITIVE_INFINITY); } public void onHitWall(HitWallEvent e) { direction = -direction; lastDirectionChange = getTime(); } // --- Events --- public void onScannedRobot(ScannedRobotEvent e) { double v1,v2;//,x,y;//,v3; //(v2 = (v1=getHeadingRadians()) + e.getBearingRadians()); //Gun //head on //v3=v2 - getGunHeadingRadians(); //if (((int)v1)%2 == 0) { //linear // v3 += /*Math.random() * */e.getVelocity()/13 * Math.sin(e.getHeadingRadians() - v2); //} setTurnGunRightRadians(Utils.normalRelativeAngle((v2 = (v1=getHeadingRadians()) + e.getBearingRadians())-getGunHeadingRadians())+e.getVelocity()/13 * Math.sin(e.getHeadingRadians() - v2)); setFire(600/(distance=e.getDistance())); //setFire(1.5); //Movement //getEnergy(); if (movingForwardHits > 1 && --moveTimer < 0){ lastDirectionChange = getTime(); moveTimer = (int)(distance*0.8/bulletVelocity); //moveTimer = 10+(int)(Math.random()*20); //depend on bullet velocity direction = -direction; } //v2 = direction*(Point2D.distance(x=getX(), y=getY(), 500, 500) > 420 ? 0.393 : -0.393); //Math.PI/8 v2 = robocode.util.Utils.normalRelativeAngle(v2-1.4*direction-v1); //turn compared to heading //v2 += robocode.util.Utils.normalRelativeAngle(Math.atan2(500-x, 500-y)-v1-1.57*direction); //Math.PI/2 //v2 = robocode.util.Utils.normalRelativeAngle(Math.atan2(400-getX(), 300-getY())-v1-1.57*direction); //Math.PI/2 v1 = Double.POSITIVE_INFINITY; if (Math.abs(v2) > 1.57) { // Math.PI/2 v2 = robocode.util.Utils.normalRelativeAngle(v2 + Math.PI); v1 = -v1; } setAhead(v1);//Double.POSITIVE_INFINITY*direction); setTurnRightRadians(v2);//robocode.util.Utils.normalRelativeAngle(v2-Math.PI/2*direction-v1)); //Radar setTurnRadarLeft(getRadarTurnRemainingRadians()); //execute(); } public void onHitByBullet(HitByBulletEvent e) { //bulletVelocity=e.getVelocity(); if (getTime()-lastDirectionChange > distance/(bulletVelocity=e.getVelocity())) { movingForwardHits++; } } }