-
-
Save CrazyPython/fadcaaf5176fa3435d92066ded8395b4 to your computer and use it in GitHub Desktop.
Spy bot - for copy-pasting
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
var us, them, red = { | |
rotation: gameInfo.red_rot, | |
x: gameInfo.red_x, | |
y: gameInfo.red_y, | |
alive: gameInfo.blue_alive | |
}, | |
blue = { | |
rotation: gameInfo.blue_rot, | |
x: gameInfo.blue_x, | |
y: gameInfo.blue_y, | |
alive: gameInfo.blue_alive | |
}; | |
if (botVars.color == "red") { | |
us = red; | |
them = blue; | |
} else if (botVars.color == "blue") { | |
us = blue; | |
them = red; | |
} | |
function distance(x1, y1, x2, y2) { | |
return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); | |
} | |
// Get our ship's position | |
var rotation, x, y, opponentAlive; | |
if (botVars.color == "red") { | |
rotation = gameInfo.red_rot; | |
x = gameInfo.red_x; | |
y = gameInfo.red_y; | |
opponentAlive = gameInfo.blue_alive; | |
} else if (botVars.color == "blue") { | |
rotation = gameInfo.blue_rot; | |
x = gameInfo.blue_x; | |
y = gameInfo.blue_y; | |
opponentAlive = gameInfo.red_alive; | |
} | |
// Calculate our rotation compared to the sun in degrees | |
var sunX = gameInfo.sun_x, | |
sunY = gameInfo.sun_y, | |
angle = Math.atan2(sunY - y, sunX - x) * 180 / Math.PI, | |
rotationToSun = (rotation - angle + 360) % 360; | |
// Check if we need to hyperspace to avoid the sun | |
var rX = x - sunX, | |
rY = y - sunY, | |
distanceFromSun = Math.sqrt(rX * rX + rY * rY) - gameInfo.sun_r; | |
if (distanceFromSun < 30) { | |
actions.push("hyperspace"); | |
console.log("Command Module is Hyperspacing.") | |
} | |
if (gameInfo[botVars["color"] + "_alive"]) { | |
var angle = Math.degrees(Math.atan2(them.y - us.y, them.x - us.x)), | |
rotationToOpponent = (us.rotation - angle + 360) % 360; | |
if (rotationToOpponent > 90 && rotationToOpponent < 270) { | |
actions.push("turn right"); | |
} else { | |
actions.push("turn left"); | |
}; | |
actions.push("fire engine"); | |
if (Math.random() > 0.3) { | |
actions.push("fire missile") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment