Vindinium is a game where you create your own AI to try to win against others. In the game, you are given an certain amount of turns to collect more gold than the other players you are competing against. The number of turns you have will depend on your server. The official Vindinium server, vindinium.org gives you 600 turns for the group (so 150 turns for you), but the private server that was used for the Summit Shasta Computer Science class gave us 1200 turns total, or 300 turns each. To get gold in order to win the game, there are a few ways you can collect and maybe even steal gold from other players. You can acquire gold by either holding mines, killing another player's bot who has mines, or by stealing mines from other players. The amount of gold you acquire depends on the number of mines you are holding. If you have 1 mine, you will get 1 gold for each time your turn passes. If you have 2 mines, you get 2 golds and so forth. If you were to attack another player and they died from your attack by reaching 0 hp, or health points, you would then own the mines that person was holding and earn gold from those mines. When planning ways to destroy your enemies, you have to keep in mind of a few things. You have 100HP at the start of the game. Whenever you move, you lose 1HP and when you claim a free mine or get hit by a player, you lose 20HP. How do you get HP back? You go to a tavern! Taverns will heal 50HP for one turn at the cost of 2 golds, a small price for staying alive. Keep in mind that each map is unique, meaning that not all maps will have the same number of mines or taverns, or even space to move. Some maps are huge and only have a total of 4 mines and 4 taverns while others are on the smaller side but have 10 mines.
var Bot = require('bot');
var PF = require('pathfinding');
var bot = new Bot('2g3qd948', '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('8dkk17d4', 'arena', 'http://52.53.211.7:9000');
//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];
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 mostMines = enemyBots[0];
for (i = 0; i < enemyBots.length; i++) {
if (mostMines.mineCount < enemyBots[i].mineCount) {
mostMines = enemyBots[i]
}
}
console.log(mostMines);
/* *
* This Code Decides WHAT to do *
* */
var task;
if (bot.yourBot.life < 26) {
task = "Go to tavern";
}
else if (bot.freeMines.length < 3) {
task = "Attack bot";
}
else if (bot.freeMines.length < 1) {
task = "Go to tavern";
}
else {
task = "freemines";
}
/*the above sends bot to taverns to regain health*/
/* *
* This Code Determines HOW to do it *
* */
// This Code find the nearest freemine and sets myDir toward that direction //
if (task === "freemines") {
var closestMine = bot.freeMines[0];
for (i = 0; i < bot.freeMines.length; i++) {
if (bot.findDistance(myPos, closestMine) > bot.findDistance(myPos, bot.freeMines[i])) {
closestMine = bot.freeMines[i];
}
}
console.log("Claiming a Free Mine!");
myDir = bot.findPath(myPos, closestMine);
}
if (task === "Go to 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 Tavern");
myDir = bot.findPath(myPos, closestTavern);
}
if (task === "Attack bot") {
myDir = bot.findPath(myPos, [mostMines.pos.x, mostMines.pos.y]);
console.log("Attacking bot");
}
/* *
* This Code 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") {
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();
My bot is relatively simple. The first priority of my bot is claiming free mines, which is labled "freemines" If my bot can't find any free mines nearby or there are no more mines to claim, there are 2 things my bot will do. My bot will either go to a tavern to restore its health, or it will attack other players, hoping that they will kill someone and get their mines. I'll go more in depth into everything below.
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);
This lovely piece of code (above) represents me and the bots I am facing. This code is important as it identifies which bot is which in the game. It is used when my bot attacks another for its mines (more on that later on).
var mostMines = enemyBots[0];
for (i = 0; i < enemyBots.length; i++) {
if (mostMines.mineCount < enemyBots[i].mineCount) {
mostMines = enemyBots[i]
}
}
console.log(mostMines);
This next string of code is used to identify which enemy bot has the most mines. This will be talked about more later as well.
var task;
if (bot.yourBot.life < 26) {
task = "Go to tavern";
}
else if (bot.freeMines.length < 3) {
task = "Attack bot";
}
else if (bot.freeMines.length < 1) {
task = "Go to tavern";
}
else {
task = "freemines";
}
This string of code is the list of priorities my bot has. My bot's first priority is its health. If my bot's health is below 26HP, it will head towards a tavern. This will give my bot enough health (hopefully) to get hit once and arrive at a tavern within 5 turns. My bot's next priority is to attack other bots if there are less than 3 free mines open. That means that the enemy bot with the most mines will get attacked, and hopefully die, which will allow me to claim his/her mines. The bot's third priority is to go to a tavern if there are no free mines open. This means that, hopefully, I will have the most mines, or at least a sufficiant amount of gold to allow me to win the game. By staying near a tavern, I am making sure my bot doesn't make unnecessary risks if it has mines that can secure a win. My bot's last priority is to go to a free mine. This is mainly so my bot can profit more off of mines that the enemy bots have already. if an enemy bot has more than one mine, I can hopefully take them without worrying too much about HP loss from fighting a bot. Besides, what's wrong with a little bloodshed?
if (task === "freemines") {
var closestMine = bot.freeMines[0];
for (i = 0; i < bot.freeMines.length; i++) {
if (bot.findDistance(myPos, closestMine) > bot.findDistance(myPos, bot.freeMines[i])) {
closestMine = bot.freeMines[i];
}}
console.log("Claiming a Free Mine!");
myDir = bot.findPath(myPos, closestMine); }
if (task === "Go to 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 Tavern");
myDir = bot.findPath(myPos, closestTavern);
This next area of code tells the bot how to find and head to the nearest free mine or tavern. In each string, the bot will look for the closest free mine or tavern respectively. Once it finds that mine or tavern, it will go to it.
if (myDir === "none") {
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;
}
This last string of code is for when there is nothing for my bot to do and there are no priorities for my bot to execute. When this happens, my bot will randomly go around the map until one of the priorities in the rest of the code can be executed.