Ocnirp/Source Code
Jump to navigation
Jump to search
- Ocnirp Sub-pages:
- Ocnirp - Version History - Source Code
package nat.nano; import robocode.AdvancedRobot; import robocode.HitWallEvent; import robocode.ScannedRobotEvent; import robocode.util.Utils; /** * Ocnirp - a robot by Nat Pavasant * "Battle for the one-on-one nano-bot crown!" * * @version 1.4 * @author Nat Pavasant */ public final class Ocnirp extends AdvancedRobot { private static final int PATTERN_DEPTH = 45; private static final double CHANGE_INTEVAL = /*0.92d*/ 0.9454623d; private static final double PREFERED_DISTANCE = 160d; private static final double FIRE_POWER = 2.4433565d; private static final double BULLET_VELOCITY = 12.5d; private static final double DISTANCE_OFFSET = 0.38435d; private static final double VELOCITY_MULTIPILER = 17.78456345d; private static final int BFT = (int) (PREFERED_DISTANCE / BULLET_VELOCITY + 2); static int dir = 100; static double en; public void run() { // setAdjustGunForRobotTurn(true); // setAdjustRadarForGunTurn(true); setTurnRadarRightRadians(Double.POSITIVE_INFINITY); } public void onScannedRobot(ScannedRobotEvent e) { int matchLen = PATTERN_DEPTH; double angle; double dist; int matchPos; // Radar setTurnRadarLeftRadians(getRadarTurnRemaining()); // Movement (Perpendicular and Random) // setTurnRightRadians(Math.cos(angle = e.getBearingRadians())); setTurnRightRadians(Math.cos(angle = e.getBearingRadians()) - Math.signum(dir * ((dist = e.getDistance()) - PREFERED_DISTANCE)) * DISTANCE_OFFSET); setAhead(dir); // Random and Energy Drop Surfing if (Math.random() > CHANGE_INTEVAL/* || en < (en = e.getEnergy())*/) { onHitWall(null); // Velocity trick setMaxVelocity(Math.random() * VELOCITY_MULTIPILER + 1); } // Eric Simonton's Pattern Matching int i; enemyHistory = String.valueOf( (char) /* Math.round */(/* 2 * */(e.getVelocity() * Math.sin(e.getHeadingRadians() - (angle += getHeadingRadians()))))).concat( enemyHistory); while ((matchPos = enemyHistory .indexOf( enemyHistory.substring(0, matchLen--), i = BFT /*(int) ((dist/* = e.getDistance() * /) / BULLET_VELOCITY) + 2 */)) < 0) ; do angle += (short) enemyHistory.charAt(--matchPos) / dist/* * 0.5 */; while (--i > 0); setTurnGunRightRadians(Utils.normalRelativeAngle(angle - getGunHeadingRadians())); // Fire setFire(FIRE_POWER); } public void onHitWall(HitWallEvent e) { dir = -dir; } static String enemyHistory = "" + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 1 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 2 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) -1 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) 0 + (char) -2 + (char) -4 + (char) -6 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -8 + (char) -7 + (char) -6 + (char) -5 + (char) -4 + (char) -3 + (char) -2 + (char) -1 + (char) 0 + (char) 2 + (char) 4 + (char) 6 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 8 + (char) 7 + (char) 6 + (char) 5 + (char) 4 + (char) 3 + (char) 2 + (char) 1 + (char) 0; }