Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
cirujator.java
package w3bex;
import robocode.*;
import robocode.util.Utils;
import java.awt.geom.*;
public class cirujator extends AdvancedRobot {
// movimientos al azar, constantes y variables
static final double Maxima_Velocidad = 8;
static final double Margen_Pared = 25;
Point2D UbicacionRobot;
Point2D UbicacionEnemigo;
double DistanciaEnemigo;
double EnemigoAbsoluto;
double AnguloMovimientoLateral = 0.2;
// variables de armas
static final int MaximaLongitud = 30;
static final int PoderFuego = 2;
static final int RapidezDisparo = 20 - PoderFuego * 3;
static int distancia;
public void run() {
setAdjustRadarForGunTurn(true);
setAdjustGunForRobotTurn(true);
do {
turnRadarRightRadians(distancia = 1000000);
} while (true);
}
public void onScannedRobot(ScannedRobotEvent e) {
// movimiento
UbicacionRobot = new Point2D.Double(getX(), getY());
EnemigoAbsoluto = getHeadingRadians() + e.getBearingRadians();
DistanciaEnemigo = e.getDistance();
UbicacionEnemigo = vectorToLocation(EnemigoAbsoluto, DistanciaEnemigo, UbicacionRobot);
move();
int DuracionPartido = MaximaLongitud;
double a;
int dist;
int PosicionPartido;
int i;
// variables
if ((a = getVelocity()) == 0) {
}
if ((dist = (int) e.getDistance()) < distancia + 32) {
a = e.getBearingRadians() + getHeadingRadians();
setTurnRadarRightRadians(Double.POSITIVE_INFINITY
* Utils.normalRelativeAngle(a - getRadarHeadingRadians()));
enemyHistory =
String.valueOf((char) Math.rint(
e.getVelocity() * Math.sin(e.getHeadingRadians() - a)))
.concat(enemyHistory);
while(
(DuracionPartido =
enemyHistory.indexOf(
enemyHistory.substring(0, DuracionPartido--),
i = dist / RapidezDisparo))
< 0);
do {
a += (double) (short) enemyHistory.charAt(--PosicionPartido) / dist;
} while (--i > 0);
setTurnGunRightRadians(
Utils.normalRelativeAngle(a - getGunHeadingRadians()));
if (getEnergy() < 0.5) {
return;
}
setFire(PoderFuego);
}
}
public void onRobotDeath(RobotDeathEvent e) {
distancia = 1000000;
}
// Siempre tratar de alejarse un poco mas del enemigo
// Cuando la pared nos fuerza encerramos al enemigo. Nunca Rebotamos en la pared.
void move() {
if (Math.random() < 0.06) {
AnguloMovimientoLateral *= -1;
}
Point2D DestinoRobot = null;
double prueba = 0;
do {
DestinoRobot = vectorToLocation(absoluteBearing(UbicacionEnemigo , UbicacionRobot) + AnguloMovimientoLateral,
DistanciaEnemigo * (1.1 - prueba / 100.0), UbicacionEnemigo);
prueba++;
} while (prueba < 100 && !fieldRectangle(Margen_Pared).contains(DestinoRobot));
goTo(DestinoRobot);
}
RoundRectangle2D fieldRectangle(double margen) {
return new RoundRectangle2D.Double(margen, margen,
getBattleFieldWidth() - margen * 2, getBattleFieldHeight() - margen * 2, 75, 75);
}
void goTo(Point2D destino) {
double angulo = Utils.normalRelativeAngle(absoluteBearing(UbicacionRobot, destino) - getHeadingRadians());
double AnguloGiro = Math.atan(Math.tan(angulo));
setTurnRightRadians(AnguloGiro);
setAhead(UbicacionRobot.distance(destino) * (angulo == AnguloGiro ? 1 : -1));
// Presionar el freno si necesitamos girar Rapidamente
setMaxVelocity(Math.abs(getTurnRemaining()) > 33 ? 0 : Maxima_Velocidad);
}
static Point2D vectorToLocation(double angle, double length, Point2D sourceLocation) {
return vectorToLocation(angle, length, sourceLocation, new Point2D.Double());
}
static Point2D vectorToLocation(double angle, double length, Point2D sourceLocation, Point2D targetLocation) {
targetLocation.setLocation(sourceLocation.getX() + Math.sin(angle) * length,
sourceLocation.getY() + Math.cos(angle) * length);
return targetLocation;
}
static double absoluteBearing(Point2D source, Point2D target) {
return Math.atan2(target.getX() - source.getX(), target.getY() - source.getY());
}
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;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.