Difference between revisions of "Help:Code Shrinking"
Jump to navigation
Jump to search
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...") |
Dsekercioglu (talk | contribs) |
||
Line 1: | Line 1: | ||
− | I was trying to make a nano bot and it is | + | 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. | 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. | If you find a way to shrink it please tell it to me. | ||
Line 16: | Line 16: | ||
extends AdvancedRobot { | extends AdvancedRobot { | ||
− | + | int[] mp = new int[30]; //movePattern | |
int i1 = 0; | int i1 = 0; | ||
− | + | String history = "�������������������������������������������������������������������������������������������"; | |
− | |||
− | String history = "�������������������������������������������������������������������������������������������"; | ||
public void run() { | public void run() { | ||
setAdjustGunForRobotTurn(true); | setAdjustGunForRobotTurn(true); | ||
setAdjustRadarForGunTurn(true); | setAdjustRadarForGunTurn(true); | ||
− | |||
for (int i = 0; i < 30; i++) { | for (int i = 0; i < 30; i++) { | ||
mp[i] = (Math.random() < 0.5 ? 1 : -1); | mp[i] = (Math.random() < 0.5 ? 1 : -1); | ||
Line 36: | Line 33: | ||
setAhead(mp[i1 / 8] * 20); | setAhead(mp[i1 / 8] * 20); | ||
i1 = (i1 + 1) % 240; | i1 = (i1 + 1) % 240; | ||
− | int a = (int) Math.round(e.getVelocity() * Math.sin(e.getBearingRadians())) | + | int a = (int) Math.round(e.getVelocity() * Math.sin(e.getBearingRadians())) + 8; |
− | + | history += (char) (a); | |
− | history += (char)(a | ||
byte b = (byte) (e.getDistance() / 14); | byte b = (byte) (e.getDistance() / 14); | ||
− | int matchi = history.substring(0, history.length() - b).lastIndexOf(a | + | int matchi = history.substring(0, history.length() - b).lastIndexOf(a); |
double c = 0; | double c = 0; | ||
int d = 0; | int d = 0; |
Revision as of 10:30, 11 February 2017
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; }
}