Skip to content

Instantly share code, notes, and snippets.

@jiaaro
Last active December 16, 2015 06:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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};
}
@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