Computer Science

| Vindinium Bots |


vindinium

Vindinium

What is Vindinium?

Vindinium is a bot game where you create your own AI to compete against others. Your objective is to gain the most gold in the allocated amount of turns (On the Vindinium Official server it is 600 turns while the provided private server we were using is 1,200 turns). All of the maps you play on are random, they can have 4 mines, or they can have 20. You acquire gold through the holding of mines and each mine gives you 1 gold per turn. You can acquire gold in 3 ways; claiming free mines, stealing claimed mines, or killing a person who has mines. If you die and you have mines, the person who killed you gets those mines. Always be careful of your HP, whenever you grab a mine or attacked by a player, you lose 20HP. You only have 100HP and already you lose 1HP per turn by moving. To regain HP, you need to go heal at a Tavern. Tavern's cost 2 gold and will heal 50HP for you in one turn.

The Code

Here is the code that makes up my bot:

                
var Bot = require('bot');
 var PF = require('pathfinding');
  var bot = new Bot('bkt2ad5a', '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);

        // Looked for mines that were taken by other players
        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);

            // Find 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]
            }
        }


        /*                                      *
         * This Code Decides WHAT to do         *
         *                                      */
        var task;
                if(bot.yourBot.life <= 31){
        task = "tavern";
                    
                }
                else if(bot.freeMines <= 0){
        task = "attack";
                    
                }
                else{
        task = "freemines";
                    
                }
        
        /*                                     * 
        * This Code Decides WHAT to do         *
        *                                      */
        // This Code sends the Bot to the nearest Tavern to heal //
        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("Drinking away my life!");
            myDir = bot.findPath(myPos, closestTavern);
        }
        
        
        /*                                      *
         * 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 Code Determines HOW to do it    *
         *                                      */
        // This Code find the nearest player and sets myDir toward that direction //
        if(task === "attack") {
            console.log("Stabbing my adversary!");
            myDir = bot.findPath(myPos , [closestBot.pos.x , closestBot.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;
        }

        
        
        ///////////* DON'T REMOVE ANTYTHING BELOW THIS LINE *//////////////
        resolve();
    });
}
bot.runGame();

                
            

What my Bot does!

My bot is a simple setup with no advanced commands. The first task my bot to do is to claim the closest mine to it, BUT if there are no mines are running low on health it will one of two things. If there are no other mines available for claiming, then the bot will attack bot closest to it. If the bot has less than 31 health then the bot will go to a tavern and heal up then continue claiming mines or attacking bots.


Code Breakdown!

            
        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 string of commands is telling the bot that there are other bots out there too and identifies them. By identifying the other bots in the game, you can set up an attack command string to attack other bots. Later, I will be showing off the part of the script that specifically targets and attacks the bot that is closest to it.




                
        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);
                
            

This current string tells the bot how many mines each bot in the game has. This information can come in handy as you can use it to attack the player with the most mines but I did not utilize this code string at all but kept it in just in case of any future change.




                
        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]
            }
        }
                
            

This part here labels the closest bot to it as an enemy. This is only possible with the help of the otehr piece of code that looks and identifies the other bots in the game.




                
        var task;
                if(bot.yourBot.life <= 31){
        task = "tavern";
                    
                }
                else if(bot.freeMines <= 0){
        task = "attack";
                    
                }
                else{
        task = "freemines";
                    
                }
                
            

This is the thought process of the bot. As seen here, the bot will first:

After running through this thought process and executing whatever line of code it needs to fit the coded parameters, it will repeat the process again and again.




                
        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("Drinking away my life!");
            myDir = bot.findPath(myPos, closestTavern);
        }
                
            

This script tells the bot where the closest tavern is. The script works by looking at all of the taverns in the map and then choosing the closest one to heal at.




                
        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 script looks for free mines and goes towards the closest one to claim.




                
        if(task === "attack") {
            console.log("Stabbing my adversary!");
            myDir = bot.findPath(myPos , [closestBot.pos.x , closestBot.pos.y]);
        }
                
            

This code string is fairly simple, if the time comes to attack, this string will run. This string tells the bot to go towards the closest bot to attack 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 code is the last part of the string that tells the bot to move around at random. If the script runs out of options on what to do, it will go in go in a random direction until the main script can actually pick up something to do.