Difference between revisions of "Talk:One on One Radar"
Jump to navigation
Jump to search
(What was wrong with my original width lock code?) |
(→What was wrong with my original width lock code?: One more thing) |
||
Line 74: | Line 74: | ||
— <span style="font-family: monospace">[[User:Chase-san|Chase]]-[[User_talk:Chase-san|san]]</span> 15:04, 2 July 2011 (UTC) | — <span style="font-family: monospace">[[User:Chase-san|Chase]]-[[User_talk:Chase-san|san]]</span> 15:04, 2 July 2011 (UTC) | ||
+ | |||
+ | : On a side note, i'll probably apply to it some of the general improvements to the code that were made, and maybe break things down a bit more using an if statement instead of a ternary. — <span style="font-family: monospace">[[User:Chase-san|Chase]]-[[User_talk:Chase-san|san]]</span> 15:06, 2 July 2011 (UTC) |
Latest revision as of 16:06, 2 July 2011
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.