package kc.nano; import robocode.util.Utils; import robocode.AdvancedRobot; import robocode.ScannedRobotEvent; import robocode.HitWallEvent; import robocode.HitByBulletEvent; import robocode.BulletHitEvent; public class WaveSnake extends AdvancedRobot { static double moveFactor = 20; static double enemyEnergy; static int vel; static int lastVel; static int[][] hitData = new int[16][4]; public void run() { turnRadarRightRadians(Double.POSITIVE_INFINITY); } public void onScannedRobot(ScannedRobotEvent e) { setTurnRightRadians(Math.cos(e.getBearingRadians()) - ((e.getDistance() - 150) * moveFactor / 30000)); setTurnRadarLeft(getRadarTurnRemaining()); setTurnGunRightRadians(Utils.normalRelativeAngle((1.3 * (Math.random() - 0.5)) + e.getBearingRadians() + getHeadingRadians() - getGunHeadingRadians())); setFire(2.4); if(enemyEnergy > (enemyEnergy = e.getEnergy())) { lastVel = vel + (4 * (int)(e.getDistance() / 267)); int testVel = 3; do { if(hitData[lastVel][testVel] < hitData[lastVel][vel]) { vel = testVel; } } while(testVel-- > 0); if(vel < 2) { onHitWall(null); } } setMaxVelocity(8 * (vel - 1.5)); setAhead(moveFactor); } public void onBulletHit(BulletHitEvent e) { enemyEnergy -= 11.4; } public void onHitByBullet(HitByBulletEvent e) { hitData[lastVel][vel]++; } public void onHitWall(HitWallEvent e) { moveFactor = -moveFactor; } }
Drat, I had dibs. Mine was gonna be absolute bearing based though. :P --Chase-san