Help:Code Shrinking
Revision as of 10:30, 11 February 2017 by Dsekercioglu (talk | contribs)
I was trying to make a nano bot and it is 313 bytes =( I am not very good at shrinking code and this is the best that I could do. If you find a way to shrink it please tell it to me.
package dsekercioglu;
import robocode.AdvancedRobot; import robocode.HitByBulletEvent; import robocode.HitWallEvent; import robocode.ScannedRobotEvent; import static robocode.util.Utils.normalRelativeAngle;
public class Hammer
extends AdvancedRobot {
int[] mp = new int[30]; //movePattern int i1 = 0; String history = "�������������������������������������������������������������������������������������������";
public void run() { setAdjustGunForRobotTurn(true); setAdjustRadarForGunTurn(true); for (int i = 0; i < 30; i++) { mp[i] = (Math.random() < 0.5 ? 1 : -1); } setTurnRadarRightRadians(Double.POSITIVE_INFINITY); }
public void onScannedRobot(ScannedRobotEvent e) { setTurnRight(e.getBearing() + 90); setAhead(mp[i1 / 8] * 20); i1 = (i1 + 1) % 240; int a = (int) Math.round(e.getVelocity() * Math.sin(e.getBearingRadians())) + 8; history += (char) (a); byte b = (byte) (e.getDistance() / 14); int matchi = history.substring(0, history.length() - b).lastIndexOf(a); double c = 0; int d = 0; while ((++d) < b) { c += ((double) history.codePointAt(matchi + d) - 8) / b / 14; } setTurnGunRightRadians(normalRelativeAngle(e.getBearingRadians() + getHeadingRadians() + c - getGunHeadingRadians())); setFire(2); setTurnRadarLeftRadians(getRadarTurnRemaining()); }
public void onHitWall(HitWallEvent e) { onHitByBullet(null); }
public void onHitByBullet(HitByBulletEvent e) { mp[i1 / 8] *= -1; }
}