Difference between revisions of "SuperWalls"
Jump to navigation
Jump to search
(revise code) |
(update the code) |
||
| Line 1: | Line 1: | ||
SuperWalls is a part of the [[Super Sample Bots]] set by CrazyBassoonist. It is intended to provide new robocoders with a new challenge after beating all of the sample robots. | SuperWalls is a part of the [[Super Sample Bots]] set by CrazyBassoonist. It is intended to provide new robocoders with a new challenge after beating all of the sample robots. | ||
| − | Thanks to [[ | + | Thanks to [[Nat]] for cleaning up the bad coding caused by my horrible coding skills. |
| − | |||
| + | UPDATE: I guaranteed that this robot will not hit walls over than 2 times per round (when no hit-robot, too) » <span style="font-size:0.9em;color:darkgreen;">[[User:Nat|Nat]] | [[User_talk:Nat|Talk]]</span> » 19:45, 1 March 2009 (UTC) | ||
== Movement== | == Movement== | ||
| Line 32: | Line 32: | ||
boolean gunIdent; //Used to tell which gun we are using | boolean gunIdent; //Used to tell which gun we are using | ||
double moveAmount; // How much to move | double moveAmount; // How much to move | ||
| − | + | ||
| − | |||
| − | |||
| − | |||
public void run() { | public void run() { | ||
setAdjustRadarForRobotTurn(true); | setAdjustRadarForRobotTurn(true); | ||
| Line 45: | Line 42: | ||
setScanColor(Color.cyan); | setScanColor(Color.cyan); | ||
| − | + | setTurnRadarRight(Double.POSITIVE_INFINITY); | |
| − | |||
// turnLeft to face a wall. | // turnLeft to face a wall. | ||
| Line 52: | Line 48: | ||
// getHeading() divided by 90. | // getHeading() divided by 90. | ||
turnLeft(getHeading() % 90); | turnLeft(getHeading() % 90); | ||
| − | + | ||
while (true) { | while (true) { | ||
| − | + | if (Utils.isNear(getHeadingRadians(), 0D) || Utils.isNear(getHeadingRadians(), Math.PI)) { | |
| − | + | ahead(Math.max(getBattleFieldHeight() - getY(), getY()) - 28); | |
| − | + | } else { | |
| − | + | ahead(Math.max(getBattleFieldWidth() - getX(), getX()) - 28); | |
| − | + | } | |
| − | + | turnRight(90); | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
} | } | ||
} | } | ||
| Line 77: | Line 63: | ||
*/ | */ | ||
public void onScannedRobot(ScannedRobotEvent e) { | public void onScannedRobot(ScannedRobotEvent e) { | ||
| − | double absBearing = e.getBearingRadians()+getHeadingRadians();// The enemies location relative to us | + | double absBearing = e.getBearingRadians() + getHeadingRadians(); // The enemies location relative to us |
| − | double latVel = e.getVelocity()*Math.sin(e.getHeadingRadians()-absBearing);// The enemies lateral velocity | + | double latVel = e.getVelocity() * Math.sin(e.getHeadingRadians() - absBearing); // The enemies lateral velocity |
| − | double radarTurn = absBearing - getRadarHeadingRadians();// The amount to turn our radar | + | double radarTurn = absBearing - getRadarHeadingRadians(); // The amount to turn our radar |
| + | |||
double HGRating = (double) HGHits / HGShots; | double HGRating = (double) HGHits / HGShots; | ||
double LGRating = (double) LGHits / LGShots; | double LGRating = (double) LGHits / LGShots; | ||
| − | + | ||
| − | + | if ((getRoundNum() == 0 || LGRating > HGRating) && getRoundNum() != 1){ // In the first round or when linear gun got more hitting percentage use linear targeting | |
| − | |||
| − | |||
| − | |||
| − | |||
double bulletPower = Math.min(3, e.getEnergy() / 4); | double bulletPower = Math.min(3, e.getEnergy() / 4); | ||
| − | setTurnGunRightRadians(Utils.normalRelativeAngle(absBearing - getGunHeadingRadians() + Math.asin(latVel / (20 - 3 * bulletPower)))); | + | setTurnGunRightRadians(Utils.normalRelativeAngle(absBearing - getGunHeadingRadians() + Math.asin(latVel / (20 - 3 * bulletPower)))); |
LGShots++; | LGShots++; | ||
gunIdent = true; | gunIdent = true; | ||
| − | setFire(bulletPower);// Fire the minimum amount of energy needed to finish off the other robot | + | setFire(bulletPower); // Fire the minimum amount of energy needed to finish off the other robot |
| − | + | } else { // in second round or when the head-on gun got more hitting percentage, use head-on gun. | |
| − | |||
setTurnGunRightRadians(Utils.normalRelativeAngle(absBearing - getGunHeadingRadians())); | setTurnGunRightRadians(Utils.normalRelativeAngle(absBearing - getGunHeadingRadians())); | ||
HGShots++; | HGShots++; | ||
gunIdent = false; | gunIdent = false; | ||
| − | setFire(e.getEnergy() / 4);// Fire the minimum amount of energy needed to finish off the other robot | + | setFire(e.getEnergy() / 4); // Fire the minimum amount of energy needed to finish off the other robot |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
} | } | ||
| − | setTurnRadarRightRadians(Utils.normalRelativeAngle(radarTurn) * 2);// Make the radar lock on | + | setTurnRadarRightRadians(Utils.normalRelativeAngle(radarTurn) * 2); // Make the radar lock on |
| − | |||
} | } | ||
| − | public void onBulletHit(BulletHitEvent e){ | + | public void onBulletHit(BulletHitEvent e) { |
| − | if(gunIdent){ | + | if(gunIdent) { |
LGHits = LGHits+1; | LGHits = LGHits+1; | ||
| − | } | + | } else { |
| − | |||
HGHits = HGHits+1; | HGHits = HGHits+1; | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
} | } | ||
} | } | ||
} | } | ||
</pre> | </pre> | ||
| + | |||
| + | |||
| + | __NOTOC__ __NOEDITSECTION__ | ||
Revision as of 20:45, 1 March 2009
SuperWalls is a part of the Super Sample Bots set by CrazyBassoonist. It is intended to provide new robocoders with a new challenge after beating all of the sample robots.
Thanks to Nat for cleaning up the bad coding caused by my horrible coding skills.
UPDATE: I guaranteed that this robot will not hit walls over than 2 times per round (when no hit-robot, too) » Nat | Talk » 19:45, 1 March 2009 (UTC)
Movement
SuperWalls moves like Walls, but without a constant speed and it changes directions every now and then.
Targeting
SuperWalls uses two guns, a Linear Targeting gun and a Head-On Targeting gun. It keeps track of the number and of shots and hits of each gun, and uses whichever gun works better.
Code
package wiki.SuperSampleBot;
import robocode.*;
import robocode.util.*;
import java.awt.*;
/**
* SuperWalls - a sample robot by CrazyBassoonist based on the sample robot Walls by Mathew Nelson and maintained by Flemming N. Larsen
* Moves around the outer edge with two targeting systems
*/
public class SuperWalls extends AdvancedRobot {
static int HGShots; //Number of shots with Head-On Targeting
static int LGShots; //Number of shots with Linear Targeting
static int HGHits; //Number of hits with Head-On Targeting
static int LGHits; //Number of hits with Linear Targeting
boolean gunIdent; //Used to tell which gun we are using
double moveAmount; // How much to move
public void run() {
setAdjustRadarForRobotTurn(true);
setAdjustRadarForGunTurn(true);
setBodyColor(Color.black);
setGunColor(Color.black);
setRadarColor(Color.orange);
setBulletColor(Color.cyan);
setScanColor(Color.cyan);
setTurnRadarRight(Double.POSITIVE_INFINITY);
// turnLeft to face a wall.
// getHeading() % 90 means the remainder of
// getHeading() divided by 90.
turnLeft(getHeading() % 90);
while (true) {
if (Utils.isNear(getHeadingRadians(), 0D) || Utils.isNear(getHeadingRadians(), Math.PI)) {
ahead(Math.max(getBattleFieldHeight() - getY(), getY()) - 28);
} else {
ahead(Math.max(getBattleFieldWidth() - getX(), getX()) - 28);
}
turnRight(90);
}
}
/**
* onScannedRobot: Fire!
*/
public void onScannedRobot(ScannedRobotEvent e) {
double absBearing = e.getBearingRadians() + getHeadingRadians(); // The enemies location relative to us
double latVel = e.getVelocity() * Math.sin(e.getHeadingRadians() - absBearing); // The enemies lateral velocity
double radarTurn = absBearing - getRadarHeadingRadians(); // The amount to turn our radar
double HGRating = (double) HGHits / HGShots;
double LGRating = (double) LGHits / LGShots;
if ((getRoundNum() == 0 || LGRating > HGRating) && getRoundNum() != 1){ // In the first round or when linear gun got more hitting percentage use linear targeting
double bulletPower = Math.min(3, e.getEnergy() / 4);
setTurnGunRightRadians(Utils.normalRelativeAngle(absBearing - getGunHeadingRadians() + Math.asin(latVel / (20 - 3 * bulletPower))));
LGShots++;
gunIdent = true;
setFire(bulletPower); // Fire the minimum amount of energy needed to finish off the other robot
} else { // in second round or when the head-on gun got more hitting percentage, use head-on gun.
setTurnGunRightRadians(Utils.normalRelativeAngle(absBearing - getGunHeadingRadians()));
HGShots++;
gunIdent = false;
setFire(e.getEnergy() / 4); // Fire the minimum amount of energy needed to finish off the other robot
}
setTurnRadarRightRadians(Utils.normalRelativeAngle(radarTurn) * 2); // Make the radar lock on
}
public void onBulletHit(BulletHitEvent e) {
if(gunIdent) {
LGHits = LGHits+1;
} else {
HGHits = HGHits+1;
}
}
}