Talk:One on One Radar
Jump to navigation
Jump to search
What was wrong with my original width lock code?
Not that I am bitter, much to the contrary, since I like to see things evolve and change and be made better. But really I think the code change that happened somewhere along the line was a step backward.
My original code was written to be very clear and easy to understand, the new code isn't as simple, as it has many things combined on the same line. I think the main offender was Duyn.
My original code:
import robocode.util.Utils;
public void run() {
// ...
// Basic spinning radar
while(true) {
turnRadarRightRadians(Double.POSITIVE_INFINITY);
}
}
public void onScannedRobot(ScannedRobotEvent e) {
// ...
// Absolute angle towards target
double absoluteBearing = getHeadingRadians() + e.getBearingRadians();
// Subtract current radar heading to get turn required, then normalize
double radarTurn = Utils.normalRelativeAngle(absoluteBearing - getRadarHeadingRadians());
// Width of the bot, plus twice the arc it can move in a tick, limit it to the max turn
double arcToScan = Math.min(Math.atan(36.0 / e.getDistance()), PI/4.0);
// We want to sent the radar even further in the direction it's moving
radarTurn += (radarTurn < 0) ? -arcToScan : arcToScan;
setTurnRadarRightRadians(radarTurn);
// ...
}
The new code visible on the page at the moment:
import robocode.util.Utils;
public void run() {
// ...
do {
// ...
if (getRadarTurnRemaining() == 0.0)
setTurnRadarRightRadians(Double.POSITIVE_INFINITY);
execute();
} while (true);
}
public void onScannedRobot(ScannedRobotEvent e) {
double radarTurn = Utils.normalRelativeAngle(
// Absolute bearing to target
getHeadingRadians() + e.getBearingRadians()
// Subtract current radar heading to get turn required
- getRadarHeadingRadians() );
// Distance we want to scan from middle of enemy to either side
double extraTurn = Math.min(Math.atan(36.0 / e.getDistance()), Math.PI/4.0);
setTurnRadarRightRadians(radarTurn + (radarTurn < 0 ? -extraTurn : extraTurn));
// ...
}
I thought the ideas was to make the code easier to read and understand what it does, rather then making the code similar to other implementation for comparison.
I wanted to get a consensus before just changing it back, and avoid any kind of edit war here.
- [View source↑]
- [History↑]
There are no threads on this page yet.