Last active
December 16, 2015 06:39
-
-
Save jiaaro/5392862 to your computer and use it in GitHub Desktop.
Partially de-obfuscated simpleTarget() from nodewar.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// nodewar.com library function… | |
// o.lib.targeting.simpleTarget(ship, pos) | |
// | |
// mostly deobfuscated/deminified | |
// | |
function simpleTarget(ship, pos) { | |
var i, r, h, | |
torque = 0, | |
thrust = 0, | |
dir = o.lib.targeting.dir(ship, pos); | |
if (Math.abs(dir) < Math.PI/8) { | |
thrust = 1; | |
} | |
else if (Math.abs(dir) < Math.PI/4) { | |
thrust = .5; | |
} | |
// ship is not turning | |
if (ship.a_vel === 0) | |
torque = (dir < 0) ? -1 : 1; | |
// ship is turning right, but target is left | |
else if (dir < 0 && ship.a_vel > 0) | |
torque = -1; | |
// ship is turning left, but target is right | |
else if (dir > 0 && ship.a_vel < 0) | |
torque = 1; | |
// we're turning the right way. just fine tuning... | |
else { | |
i = o.RULES.TORQUE_RANGE[1] / ship.m_i; | |
h = Math.abs(ship.a_vel) / i; | |
r = Math.abs(ship.a_vel) * h + .5 * -i * h * h; | |
if (Math.abs(dir) > r) { | |
torque = (dir > 0) ? 1 : -1; | |
} | |
else { | |
torque = (dir > 0) ? -1 : 1; | |
} | |
} | |
return {thrust: thrust, torque: torque, label: null}; | |
} |
There's also surely some advantage to be gained by adjusting weighting according to the moon field size, as well as taking gravity into account. More accurate navigation would quite likely trip up any of the existing contenders.
Thanks @malgorithms
@aniero yeah, that's why I'm trying to understand simpleTarget =D
my first goal is to change the targeting from the current "skate toward the puck" to "skate to where the puck is going". And use that when attacking.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think the real improvements are to be gained with changing how the thrust works. The rotation code, as far as I could figure, was just about ideal: at the timescales involved (
t=0.005
inx = x0 + vt + 1/2at^2
) and taking the moment of inertia into account, the torque should always be maxed out in either direction.It occurs to me that this may not hold with smaller fragments, though… hmm!
As a side note, I'm amused at how many (all?) of the leaders are based on the open-source bots, just with slightly different weightings.