What is Vindinium

What is Vindinium? Vindinium is an Artificial Intelligence (AI) game where there are four bots programed to fight for control of an island. The coding that is used to program these bots was javascript.

How to play?

In order to win, the player must obtained the most gold and by doing so they must capture mines.

In the island there can be as much only four mines or more, when enemy players captured other mines someone can program their robot to capture enemy mines.

In each mine there are goblins where the player must fight them off in order to obtain them, however they lose 20 hp to each mine.

At the start of the of game, each player has 100 health points, each turn, the player loses one health point. When the hero or the player captures a mine it loses 20 health points. If a player loses to a enemy player, their health points will go to zero, respawn, but will lose all their mines and if the player wins, the player will lose one hp and win all their all mines. In order to restore their health, the hero needs to go to a tavern, and the tavern restores 50 hp.

When a player dies, they will respawn with all their health and gold but no mines.

My Bot

The bot that I created was programed to attack enemy mines, capture free mines, go to a tavern when its health is below 40 hp and attacks enemy bots when their health is below 20 hp.

My code

var Bot = require('bot');
var PF = require('pathfinding');
 // var bot = new Bot('4rfiyfmc', '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('7wf4q75q', '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 closeEnemy=closestPlayer();
        
        var enemyMines=[]
        enemyMines=enemyMines.concat(enemyBots[0].mines);
        enemyMines=enemyMines.concat(enemyBots[1].mines);
        enemyMines=enemyMines.concat(enemyBots[2].mines);
        enemyMines=enemyMines.concat(bot.freeMines);
        /*                                      *
         * This Code Decides WHAT to do         *
         *                                      */
        var task;
        if(bot.yourBot.life < 40){
            task="taverns"
        }else if(bot.findDistance(myPos,[closeEnemy.pos.x,closeEnemy.pos.y])<5&&closeEnemy.pos.x.life bot.findDistance(myPos, bot.freeMines[i])) {
                    closestMine = bot.freeMines[i];
                }
            }
            console.log("Claiming a Free Mine!");
            myDir = bot.findPath(myPos, closestMine);
        }else if(task==="taverns"){
            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];
                }
            }
            myDir=bot.findPath(myPos,closestTavern)
        }else if(task==="hunt"){
            myDir=bot.findPat(myPos,[closeEnemy.pos.x,closeEnemy.pos.y]);
        }
        
        function closestPlayer(){
            var closestPlayer = enemyBots[0];
            for(i = 0; i < enemyBots.length; i++) {
                if(bot.findDistance(myPos, [closestPlayer.pos.x,closestPlayer.pos.y]) > bot.findDistance(myPos, [enemyBots[i].pos.x,enemyBots[i].pos.y])) {
                    closestPlayer = enemyBots[i];
                }
            }
            console.log("Claiming a Free Mine!");
            return closestPlayer;
        }
        /*                                                                                                                              *
         * 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();

How it works?

How does this all work?

        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 closeEnemy=closestPlayer();
        
        var enemyMines=[]
        enemyMines=enemyMines.concat(enemyBots[0].mines);
        enemyMines=enemyMines.concat(enemyBots[1].mines);
        enemyMines=enemyMines.concat(enemyBots[2].mines);
        enemyMines=enemyMines.concat(bot.freeMines);
                

The first part of the code, it tells if you are bot 3 it will tell the other bots that they are bot 1, 2, and 4. The second part of the code tells the bot to look for enemy mines so it can claim their miness.

                     var task;
        if(bot.yourBot.life < 40){
            task="taverns"
        }else if(bot.findDistance(myPos,[closeEnemy.pos.x,closeEnemy.pos.y])<5&&closeEnemy.pos.x.life bot.findDistance(myPos, bot.freeMines[i])) {
                    closestMine = bot.freeMines[i];
                }
            }
            console.log("Claiming a Free Mine!");
            myDir = bot.findPath(myPos, closestMine);
        }else if(task==="taverns"){
            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];
                }
            }
            myDir=bot.findPath(myPos,closestTavern)
        }else if(task==="hunt"){
            myDir=bot.findPat(myPos,[closeEnemy.pos.x,closeEnemy.pos.y]);
        }
        
        function closestPlayer(){
            var closestPlayer = enemyBots[0];
            for(i = 0; i < enemyBots.length; i++) {
                if(bot.findDistance(myPos, [closestPlayer.pos.x,closestPlayer.pos.y]) > bot.findDistance(myPos, [enemyBots[i].pos.x,enemyBots[i].pos.y])) {
                    closestPlayer = enemyBots[i];
                }
            }
            console.log("Claiming a Free Mine!");
            return closestPlayer;
                

This huge chunk of code are the main controls of the bot, the first part tells the bot to go to a tavern because of the task it is given, the bot will go to the closest tavern when its health is below 40. The second part tells the bot to claim free mines, which means that they are not occupied by enemy players. The third part, it determines whether a bot should attack a player or not, because it tells the bot to attack when its less than 5 spaces away and has health below 20.

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

The last part of my coding, this part tells the bot to move and the movements are random but will detect if there are enemy bots or mines close by.

What have I learned about AI?

What I learn throughout this entire project of making my own bot and programming it to have its ability to live and attack, is that it is very hard to make something like this, and now imagine creating actual artificial intelligence to roam in our planet. My bot had many fails and its function kept getting worse and worse throughout the project but then later fixed due to extremely minor errors. However in the end, it did what I wanted to do, claim enemy mines, attack enemy bots and heal itself at taverns.