![]() ![]() double targetBearing = e.getBearingRadians() + getHeadingRadians() ĭouble perpendicularMotionCoefficient = Math.sin(e.getHeadingRadians() - targetBearing) Since robocode appears to neglect the difference between course and heading, the innermost sine Math.sin(e.getHeadingRadians() - targetBearing) gives a signed coefficient indicating what component of the target's velocity is perpendicular to its bearing and therefore requires firing-angle adjustment. SetTurnGunRightRadians(Math.sin(targetBearing - getGunHeadingRadians() + Math.asin(predictedVelocity / 14.0D * Math.sin(e.getHeadingRadians() - targetBearing)))) double targetBearing = e.getBearingRadians() + getHeadingRadians() ĭouble predictedVelocity = vel * 0.4D + e.getVelocity() * 0.6D We also have the variable vel unaccounted for, but based on the rest of the code, it seems to be the target's velocity when last scanned (and under the rash assumption that only one-on-one matches will be played) it's combined into a weighted average with the current velocity to give a rough predicted velocity, so there's probably some target-leading logic going on here. ![]() SetTurnGunRightRadians(Math.sin(targetBearing - getGunHeadingRadians() + Math.asin((vel * 0.4D + e.getVelocity() * 0.6D) / 14.0D * Math.sin(e.getHeadingRadians() - targetBearing)))) Refactored: double targetBearing = e.getBearingRadians() + getHeadingRadians() Since e.getBearingRadians() returns the target's bearing relative to your heading, var is the absolute target's bearing. Looks like var is being used to hold the result of the subexpression e.getBearingRadians() + getHeadingRadians(). ( EDIT: I've been out of robocode too long obfuscated-looking messes are likely the result of hand-optimizing for code size.) Let's try to unpick that one messy line, starting here: setTurnGunRightRadians(Math.sin((Guppy.var = e.getBearingRadians() + getHeadingRadians()) - getGunHeadingRadians() + Math.asin((vel * 0.4D + e.getVelocity() * 0.6D) / 14.0D * Math.sin(e.getHeadingRadians() - var)))) Painful style, too, assigning a variable and then using it within the same expression and randomly reusing static variables for different purposes. ![]() Of note to those familiar with trigonometry but not Robocode: Robocode's angular values are nonnegative and increase clockwise, rather than zero-centered and increasing counterclockwise as in trigonometric convention. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |