Skip to content

Instantly share code, notes, and snippets.

@CrazyPython
Created July 17, 2016 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CrazyPython/16be557152f13c4fc6d4a99fd541d613 to your computer and use it in GitHub Desktop.
Save CrazyPython/16be557152f13c4fc6d4a99fd541d613 to your computer and use it in GitHub Desktop.
Prototype of my bot - No cleanup, no nothing
/* Code completely stolen from Kamikaze. I'm sorry. (but not sorry at the same time) */
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;
var enemyDistance = distance(gameInfo["red_x"], gameInfo["red_y"], gameInfo["blue_x"], gameInfo["blue_y"]);
// 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");
if (gameInfo[botVars["color"] + "_alive"]) {
if (enemyDistance > 0) {
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")}
}
else {
botVars["normal mode"] = 0;
botVars["crazy ticks"] += 1;
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 left");
} else {
actions.push("turn right")
};
actions.push("fire missile");
if (botVars["crazy ticks"] == 30) {
botVars["normal mode"] = 1;
botVars["crazy ticks"] = 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment