Skip to content

Instantly share code, notes, and snippets.

@jiaaro
Last active December 16, 2015 06:39
Show Gist options
  • Save jiaaro/5392862 to your computer and use it in GitHub Desktop.
Save jiaaro/5392862 to your computer and use it in GitHub Desktop.
Partially de-obfuscated simpleTarget() from nodewar.com
// 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};
}
@zerowidth
Copy link

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.

@jiaaro
Copy link
Author

jiaaro commented Apr 17, 2013

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