ReWrite

Jump to navigation Jump to search

I think the super samples should all be rewritten so they are about the same level of complexity, like the original samples (newer samples vary a bit more certain reasons). Also with fully detailed comments not only on what something does, but why it does it. Many of these concepts would make absolutely not sense to newer coders and so wouldn't be as helpful if we don't explain why they are done.

Bad comment (assuming it has one, and is half this long)

// random number to add variance to movement, makes it harder to hit with bullets

Good comment

/* Adds a random amount of extra time before the robot will change direction, this makes it more difficult for targeting to predict where it will be when it does. */

Also the code should be EXPANDED for clarity. Sure you can cram that entire algorithm onto a single line, but the goal isn't a nanobot here, its for teaching purposes. Even beginner programmers can cram it all onto a single line, but even my head swims trying to piece through parenthesis insanity.

Bad Code (taken from super crazy, so my fault)

// Distance we want to scan from middle of enemy to either side
double extraTurn = Math.min(Math.atan(baseScanSpan / distance), Math.PI/4.0);
setTurnRadarRightRadians(radarTurn + (radarTurn < 0 ? -extraTurn : extraTurn));

Good Code

/* Deterime how far to scan to each side of the enemy, to get the radar 'arc' */
double extraTurn = Math.atan(baseScanSpan / distance);
/* Limit it to the maximum the radar can turn in a single round, so we can stay locked on. */
if(extraTurn > Math.PI/4.0)
    extraTurn = Math.PI/4.0;
/*
 * The radar ends on a certain side of the robot, so the radarTurn variable determines
 * the direction from where it ended towards where the enemy is now, taking advantage of
 * this we can just turn the radar even further in that direction for a cheap radar arc.
 */
if(radarTurn < 0)
    radarTurn = radarTurn - extraTurn;
else
    radarTurn = radarTurn + extraTurn;
setTurnRadarRightRadians(radarTurn);
Chase-san05:48, 4 September 2011

You do not have permission to edit this page, for the following reasons:

  • The action you have requested is limited to users in the group: Users.
  • You must confirm your email address before editing pages. Please set and validate your email address through your user preferences.

You can view and copy the source of this page.

Return to Thread:Category talk:Super Sample Bots/ReWrite/reply.