Created
July 19, 2016 18:44
-
-
Save LeoMartinDev/f738b42d86222483530c4320e9113812 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* Auto-generated code below aims at helping you parse | |
* the standard input according to the problem statement. | |
* --- | |
* Hint: You can use the debug stream to print initialTX and initialTY, if Thor seems not follow your orders. | |
**/ | |
var inputs = readline().split(' '); | |
var lightX = parseInt(inputs[0]); // the X position of the light of power | |
var lightY = parseInt(inputs[1]); // the Y position of the light of power | |
var initialTX = parseInt(inputs[2]); // Thor's starting X position | |
var initialTY = parseInt(inputs[3]); // Thor's starting Y position | |
var Position = function(x, y) { | |
this.x = x; | |
this.y = y; | |
}; | |
Position.prototype.add = function(pos) { | |
this.x += pos.x; | |
this.y += pos.y; | |
return this; | |
}; | |
Position.prototype.substract = function(pos) { | |
this.x -= pos.x; | |
this.y -= pos.y; | |
return this; | |
}; | |
Position.prototype.compare = function(pos) { | |
return this.x === pos.x && this.y === pos.y; | |
}; | |
var direction = { | |
x: { | |
'1': 'E', | |
'-1': 'W', | |
}, | |
y: { | |
'-1': 'N', | |
'1': 'S', | |
}, | |
}; | |
var Thor = function(pos) { | |
this.position = pos; | |
}; | |
Thor.prototype.move = function(vector) { | |
this.position.x += vector.x; | |
this.position.y += vector.y; | |
print((direction.y[vector.y] || "").concat(direction.x[vector.x] || "")); | |
}; | |
var ai = new Thor(new Position(initialTX, initialTY)); | |
var light = new Position(lightX, lightY); | |
// game loop | |
while (true) { | |
var remainingTurns = parseInt(readline()); | |
var axis = new Position(lightX, lightY).substract(new Position(ai.position.x, ai.position.y)); | |
var vector = new Position(Math.sign(axis.x), Math.sign(axis.y)); | |
printErr(vector.x) | |
ai.move(vector); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment