Help:Code Shrinking

From Robowiki
Revision as of 23:07, 10 February 2017 by Dsekercioglu (talk | contribs) (Created page with "I was trying to make a nano bot and it is 331 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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

I was trying to make a nano bot and it is 331 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 {
   double[] mp = new double[30]; //movePattern
   int i1 = 0;


   String history = "�������������������������������������������������������������������������������������������"; //normally there is 91 ((char)0) here but it can't be copied.
   public void run() {
       setAdjustGunForRobotTurn(true);
       setAdjustRadarForGunTurn(true);
       setAdjustRadarForRobotTurn(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()));
       System.out.println(a);
       history += (char)(a + 8);
       byte b = (byte) (e.getDistance() / 14);
       int matchi = history.substring(0, history.length() - b).lastIndexOf(a + 8);
       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;
   }

}