var Bot = require('bot'); //Declaring variable Bot which requires everything in the folder called "bot"
var PF = require('pathfinding'); //Declaring variable PF which requires everything in the folder called "pathfinding"
var bot = new Bot('YOUR_KEY_HERE', 'training', 'http://vindinium.org'); //Put your bot's code here and change training to Arena when you want to fight others.
// var bot = new Bot('YOUR_KEY_HERE', 'arena', 'PRIVATE_SERVER_HERE'); //Put your bot's code here and change training to Arena when you want to fight others.
var goDir;
var Promise = require('bluebird');
Bot.prototype.botBrain = function() {
return new Promise(function(resolve, reject) {
_this = bot;
//////* Write your bot below Here *//////
//////* Set `myDir` in the direction you want to go and then bot.goDir is set to myDir at the bottom *////////
/* *
* This Code is global data! *
* */
// Set myDir to what you want and it will set bot.goDir to that direction at the end. Unless it is "none"
var myDir;
var myPos = [bot.yourBot.pos.x, bot.yourBot.pos.y]; //Defines my position.
//Array for identifying/all enemy bots.
var enemyBots = [];
if (bot.yourBot.id != 1) enemyBots.push(bot.bot1);
if (bot.yourBot.id != 2) enemyBots.push(bot.bot2);
if (bot.yourBot.id != 3) enemyBots.push(bot.bot3);
if (bot.yourBot.id != 4) enemyBots.push(bot.bot4);
var i;
//Array for all mines, and the location for each mine.
var enemyMines = [];
enemyMines = enemyMines.concat(enemyBots[0].mines); //Location of enemyBots[0] mines
enemyMines = enemyMines.concat(enemyBots[1].mines); //Location of enemyBots[1] mines
enemyMines = enemyMines.concat(enemyBots[2].mines); //Location of enemyBots[2] mines
enemyMines = enemyMines.concat(bot.freeMines); //Location of free mines
//Determines the total amount of mines in the game currently.
var totalMines = bot.yourBot.mineCount + (enemyBots[0].mineCount + enemyBots[1].mineCount + enemyBots[2].mineCount) + bot.freeMines.length;
/* *
* This Code Decides WHAT to do *
* */
// var doubleDrink;
// var doubleDrink = bot.yourBot.doubleDrink.true;
var closestBot = enemyBots[0];
for (i = 0; i < enemyBots.length; i++) {
if (bot.findDistance(myPos, [closestBot.pos.x, closestBot.pos.y]) > bot.findDistance(myPos, [enemyBots[i].pos.x, enemyBots[i].pos.y])) { //If my position to and from the
closestBot = enemyBots[i];
}
}
var blitzTarget = enemyBots[0];
for (i = 0; i < enemyBots.length; i++) {
if (blitzTarget.mineCount < enemyBots[i].mineCount) {
blitzTarget = enemyBots[i]; //If the if statement is true than blitzTarget is equal to enemyBots[i]
}
}
var task;
if (bot.yourBot.life > closestBot.life && bot.findDistance(myPos, [closestBot.pos.x, closestBot.pos.y]) <= 2) { //If the closestBot's position is closer to me than the other enemyBots and it's 2 spaces away it will attack.
task = "attack"; //Assigning it to the task of "attack"
}
else if (bot.yourBot.life <= 40 || bot.yourBot.mineCount >= 0.5 * totalMines) { //If my health is less than or equal to 40hp OR if my minecount exceeds or is equal to 50% of all mines it will sit/go to a tavern.
task = "tavern";
}
else if (bot.yourBot.mineCount < (totalMines / 3)) { //The main purpose of this bot was to put it higher on the priority list. If my mineCount is less than 33% of all mines it will continue farming/mining till it does have at least 33%
task = "allMines";
}
else if (bot.yourBot.life > 35 && blitzTarget.mineCount > bot.yourBot.mineCount && bot.yourBot.mineCount < 0.5 * totalMines) { //If my bot's health is greater than 35 and my blitztargets minecount is greater than mine and my mineCount is less than 50% of all mines it will blitz at them meaning it will locate them, and its main purpose is to keep going for the player with the most mines till they die.
task = "blitzMode";
}
/* *
* This Code Determines HOW to do it *
* */
// This Code find the closest mine first, then and sets myDir toward that direction
if (task === "allMines") { //Making task strictly equal allMines.
var closestMine = enemyMines[0];
for (i = 0; i < enemyMines.length; i++) {
if (bot.findDistance(myPos, closestMine) > bot.findDistance(myPos, enemyMines[i]) && bot.findPath(myPos, enemyMines[i])) {
closestMine = enemyMines[i];
}
}
console.log("Claiming Mine!");
myDir = bot.findPath(myPos, closestMine); //Sets the direction of my bot towards the closest mine, enemy or free.
}
// This code finds the closest tavern and then sets my direction towards that tavern.
if (task === "tavern") {
var closestTavern = bot.taverns[0];
for (i = 0; i < bot.taverns.length; i++) {
if (bot.findDistance(myPos, closestTavern) > bot.findDistance(myPos, bot.taverns[i])) {
closestTavern = bot.taverns[i];
}
}
console.log("Going to nearest tavern!");
myDir = bot.findPath(myPos, closestTavern); //Sets the direction of my bot towards the nearest tavern.
}
// This code finds the closest bot and then sets my direction towards the closest bot.
if (task === "attack") {
console.log("Attacking the nearest bot!");
myDir = bot.findPath(myPos, closestBot.posArray); //Sets the direction of my bot towards the closest bot's position.
}
// This code finds the person with the most mines and set's my direction towards that person.
if (task === "blitzMode") {
console.log("Blitz Mode Activated!");
myDir = bot.findPath(myPos, [blitzTarget.pos.x, blitzTarget.pos.y]); //Sets the direction of my bot towards the person with the most mines.
}
// Logs when I die and respawn
if (bot.yourBot.life <= 0) {
console.log("You have died");
}
if (bot.yourBot.life === 100) {
console.log("You have respawned.")
}
/* *
* This sCode Sets your direction based on myDir. If you are trying to go to a place that you can't reach, you move randomly. *
* Otherwise you move in the direction set by your code. Feel free to change this code if you want. */
if (myDir === "none") { //If a direction is not set it will go randomly.
console.log("Going Random!");
var rand = Math.floor(Math.random() * 4);
var dirs = ["north", "south", "east", "west"];
bot.goDir = dirs[rand];
}
else {
bot.goDir = myDir;
}
///////////* DON'T REMOVE ANTYTHING BELOW THIS LINE *//////////////
resolve();
});
}
bot.runGame();