Difference between revisions of "User talk:Realmoonstruck"
Line 2: | Line 2: | ||
I have been trying to make competitive Junior Robots. This the best 1 vs 1 bot I could make till now... | I have been trying to make competitive Junior Robots. This the best 1 vs 1 bot I could make till now... | ||
+ | <code> | ||
+ | package ne0n; | ||
− | |||
import robocode.*; | import robocode.*; | ||
+ | |||
public class JuniorLinear extends JuniorRobot { | public class JuniorLinear extends JuniorRobot { | ||
+ | |||
int moveAmount; | int moveAmount; | ||
+ | |||
public void run() { | public void run() { | ||
+ | |||
setColors(black, white, red, orange, purple); | setColors(black, white, red, orange, purple); | ||
+ | |||
moveAmount = Math.max(fieldWidth, fieldHeight); | moveAmount = Math.max(fieldWidth, fieldHeight); | ||
+ | |||
turnTo(0); | turnTo(0); | ||
+ | |||
while (true) { | while (true) { | ||
+ | |||
bearGunTo(90); | bearGunTo(90); | ||
+ | |||
ahead(moveAmount); | ahead(moveAmount); | ||
+ | |||
} | } | ||
+ | |||
} | } | ||
+ | |||
public void onHitWall() { | public void onHitWall() { | ||
+ | |||
bearGunTo(90); | bearGunTo(90); | ||
+ | |||
turnRight(90); | turnRight(90); | ||
+ | |||
} | } | ||
+ | |||
public void onHitByBullet() { | public void onHitByBullet() { | ||
+ | |||
turnGunTo(hitByBulletAngle); | turnGunTo(hitByBulletAngle); | ||
+ | |||
} | } | ||
+ | |||
public void onHitRobot() { | public void onHitRobot() { | ||
+ | |||
if (scannedBearing > -90 && scannedBearing < 90) | if (scannedBearing > -90 && scannedBearing < 90) | ||
+ | |||
back(100); | back(100); | ||
+ | |||
else | else | ||
+ | |||
ahead(100); | ahead(100); | ||
+ | |||
} | } | ||
+ | |||
public void onScannedRobot() { | public void onScannedRobot() { | ||
+ | |||
double firepower = 3d-2d*((double)scannedDistance/(double)moveAmount); | double firepower = 3d-2d*((double)scannedDistance/(double)moveAmount); | ||
+ | |||
double bulletVelocity = 20-3*firepower; | double bulletVelocity = 20-3*firepower; | ||
+ | |||
double offset = Math.toDegrees(Math.asin(scannedVelocity*Math.sin(Math.toRadians(scannedHeading-scannedAngle))/bulletVelocity)); | double offset = Math.toDegrees(Math.asin(scannedVelocity*Math.sin(Math.toRadians(scannedHeading-scannedAngle))/bulletVelocity)); | ||
+ | |||
turnGunTo((int)(scannedAngle + offset)); | turnGunTo((int)(scannedAngle + offset)); | ||
fire(firepower); | fire(firepower); | ||
+ | |||
} | } | ||
+ | |||
} | } | ||
+ | |||
+ | </code> | ||
As the name suggests this uses simple trigonometric linear targeting. This has been able to beat all the Sample bots on 1 vs 1. But in melee Walls and SpinBot are beating me each time. I tried to implement some better movement and targeting strategies but couldn't get anything to work till now. | As the name suggests this uses simple trigonometric linear targeting. This has been able to beat all the Sample bots on 1 vs 1. But in melee Walls and SpinBot are beating me each time. I tried to implement some better movement and targeting strategies but couldn't get anything to work till now. | ||
Any help will be appreciated... | Any help will be appreciated... | ||
cant figure out how to get | cant figure out how to get |
Revision as of 14:53, 14 July 2010
Competitive JuniorRobot
I have been trying to make competitive Junior Robots. This the best 1 vs 1 bot I could make till now...
package ne0n;
import robocode.*;
public class JuniorLinear extends JuniorRobot {
int moveAmount;
public void run() {
setColors(black, white, red, orange, purple);
moveAmount = Math.max(fieldWidth, fieldHeight);
turnTo(0);
while (true) {
bearGunTo(90);
ahead(moveAmount);
}
}
public void onHitWall() {
bearGunTo(90);
turnRight(90);
}
public void onHitByBullet() {
turnGunTo(hitByBulletAngle);
}
public void onHitRobot() {
if (scannedBearing > -90 && scannedBearing < 90)
back(100);
else
ahead(100);
}
public void onScannedRobot() {
double firepower = 3d-2d*((double)scannedDistance/(double)moveAmount);
double bulletVelocity = 20-3*firepower;
double offset = Math.toDegrees(Math.asin(scannedVelocity*Math.sin(Math.toRadians(scannedHeading-scannedAngle))/bulletVelocity));
turnGunTo((int)(scannedAngle + offset));
fire(firepower);
}
}
As the name suggests this uses simple trigonometric linear targeting. This has been able to beat all the Sample bots on 1 vs 1. But in melee Walls and SpinBot are beating me each time. I tried to implement some better movement and targeting strategies but couldn't get anything to work till now. Any help will be appreciated... cant figure out how to get