Vindinium is a game where each player writes code for an AI
(artificial intelegence). The AI are then put to the test in
competition against eachother. In order for the AI to know what
to do, the player must write code to tell it how to react to its
surroundings, which are constantly changing as the game
progresses. This is similar to the way that the computer players
in digital versions of games such as chess or Hearts know how to
move in response to the players movements when it is their turn.
In vindinium, you win by having the most gold by the end of 1200
turns. You obtain gold by taking control of mines, which are
shown on the map. Each turn that passes, you gain one gold for
each mine you own. However, the AIs can also attack eachother,
and if you are killed, all of your mines become controled by
whoever killed you. You won't die from just one hit, so in order
to regain health, you must visit a tavern, which is represented
by a large mug, to regain health.
For the bot I created, I wrote code for it to perform a variety
of different actions, and would decide which one is the smartest
move, based on the situation. For my bot I made it so that it
would designate which bot was in control of the most mines and
attack it. But so my bot wouldn't die, I made it so that if the
bot's health was less than 10, it would prioritize finding a
tavern to heal. In addition, I took into account the scenario in
which my bot is the bot with the most mines, in which case my
bot will simply go after the closest mine not under my control.
My Bot code is shown Below.
/* *
* 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 enemyMines = [];
if(bot.yourBot.id != 1) enemyMines = enemyMines.concat(bot.bot1mines);
if(bot.yourBot.id != 2) enemyMines = enemyMines.concat(bot.bot2mines);
if(bot.yourBot.id != 3) enemyMines = enemyMines.concat(bot.bot3mines);
if(bot.yourBot.id != 4) enemyMines = enemyMines.concat(bot.bot4mines);
//Finds the closest enemy Bot
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]) ) {
closestBot = enemyBots[i];
}
}
//Finds the bot with the most mines
var mostMines = enemyBots[0];
for(i = 0; i < enemyBots.length; i++){
if(mostMines.mineCount < enemyBots[i].mineCount){
mostMines = enemyBots[i];
}
}
/* *
* This Code Decides WHAT to do *
* */
var task;
//this is a temporary note ****** I want my bot to attack only attack, and target the bot with the most mines.
if(bot.yourBot.life < 10) {
task = "gototavern"
}
else if(bot.freeMines.length < 3){
task = "attack"
}
else{
task = "freemines";
}
/* *
* 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);
}
//this will determine which tavern is closest and sets myDir toward that direction
if(task === "gototavern") {
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("Moving to Tavern!");
myDir = bot.findPath(myPos, closestTavern);
}
//attacking
if(task === "attack"){
console.log("Attacking Bot With the Most Mines!")
myDir = bot.findPath(myPos, [mostMines.pos.x, mostMines.pos.y]);
}
/* *
* 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;
}
In the end, I was able to get my bot to do exactly what I wanted
it to do, that being targeting the bot with the most mines. This
was quite confusing for me to understand at first, but as I
looked over the existing code again and again, it slowly started
making sense to me and by the time I finished coding my bot, I
felt much more confident that I knew what I was doing.