FAQ  •  Register  •  Login

MoBot

<<

thread

User avatar

Posts: 36

Joined: Sun Apr 28, 2013 3:37 pm

Location: SPAAAAAACCE!!!!!

Post Mon Dec 29, 2014 8:57 pm

MoBot

"mO-bot" - noun; A weak and quite stupid bot. It is known to take a specific path upon spawning and holds still whenever shooting. It never uses any modules.


This bot, in its current version, is only compatible with one level. I made a MOBA style level, and this bot is made to act as the weakling minions that show up in waves. The level is "BOTA"

What is a MOBA? Well, it stands for Multiplayer Online Battle Arena. Think "League of Legends" or "DOTA 2".

Get the level:
http://bitfighter.org/pleiades/levels/view/353
Get the bot:
Download the attached file.
MoBot.zip
If it isn't working, you can copy the code into a file manually. The file should be named "MoBot.bot" and be put inside your "robots" folder.
  Code:
-------------------------------------------------------------------------------
-- This bot is adapted from the code for S_bot.
-- S_bots' authors deserve their due credit.
--
-- Author:
--  thread
-------------------------------------------------------------------------------

goalPt = point.new(0,0);
prevtarget = nil;
gotoPositionWasNil = true;
o = point.new(0,0);
botPos = nil;
items = { };

--BOTA specific variables
--First, the different paths the bot can take.
top1 = {point.new(1402.5,-382.5), point.new(1020,-382.5), point.new(765,-892.5), point.new(0,-892.5), point.new(-765,-892.5), point.new(-1020,-382.5), point.new(-1402.5,-382.5), point.new(-1912.5,0)};
bot1 = {point.new(1402.5,382.5), point.new(1020,382.5), point.new(765,892.5), point.new(0,892.5), point.new(-765,892.5), point.new(-1020,382.5), point.new(-1402.5,382.5), point.new(-1912.5,0)};
top2 = {point.new(-1402.5,-382.5), point.new(-1020,-382.5), point.new(-765,-892.5), point.new(0,-892.5), point.new(765,-892.5), point.new(1020,-382.5), point.new(1402.5,-382.5), point.new(1912.5,0)};
bot2 = {point.new(-1402.5,382.5), point.new(-1020,382.5), point.new(-765,892.5), point.new(0,892.5), point.new(765,892.5), point.new(1020,382.5), point.new(1402.5,382.5), point.new(1912.5,0)};
myPath = {};
soFar = 0;
pathSize = 8;

-- This function gets run once during setup.  It is the only time we can declare variables
-- and have them be defined as globals.
function main()
    botRadius = bot:getRad();
    dirToGo = 0;
    game = bf:getGameInfo();

    difficulty         = tonumber(arg[1]) or .5;
    agression          = tonumber(arg[2]) or 0.5;
    defense            = tonumber(arg[3]) or 0;
    speed              = tonumber(arg[4]) or .75;   
    directionThreshold = tonumber(arg[5]) or .25;

    gameType = game:getGameType();
   
    averageIndex = 1;
    averageMax = 20;

    averageArray = { };
    for i = 1, averageMax do
        averageArray[i] = false;
    end

    myOrbitalDirection = 1;
end

-- bot:fireModule(Module.Shield);

function angleDifference(angleA, angleB)
    return (math.mod(math.mod(angleA - angleB, math.pi * 2) + math.pi * 3, math.pi * 2) - math.pi)
end

function fireAtObjects()
   result = false;
    table.clear(items);
    bot:findVisibleObjects(items, ObjType.Robot, ObjType.Turret, ObjType.Ship, ObjType.Core);

    -- Cycle through list of potential items until we find one that we can attack
    for index, enemy in ipairs(items) do
        if(fireAtObject(enemy, Weapon.Phaser)) then
         result = true;
            break;
        end
    end
   
   return result;
end

-- Fires at the specified object with the specified weapon if the obj is a good target. Returns whether it fired or not.
-- This is more than I need for my purposes, but it covers all the cases I need, so I will leave it as is.
function fireAtObject(obj, weapon)
    local classId = obj:getObjType()

    if(classId == ObjType.Turret or classId == ObjType.ForceFieldProjector) then
        --Ignore all same-team engineered objects and essentially dead objects
        if (obj:getTeamIndex() == bot:getTeamIndex() or obj:getHealth() < .1) then
            return false;
        end
    end
    --No shooting various team related objects
    if (obj:getTeamIndex() == bot:getTeamIndex() and game:isTeamGame()) or
        obj:getTeamIndex() == Team.Neutral then
        if (classId == ObjType.Ship or classId == ObjType.Robot or
            classId == ObjType.Core or classId == ObjType.SpyBug) then
            return false;
        end
    end
    --No shooting non-flag carriers in single player rabbit
    if gameType == GameType.Rabbit and not game:isTeamGame() and
        (classId == ObjType.Ship or classId == ObjType.Robot) and
        not bot:hasFlag() and not obj:hasFlag() then
        return false;
    end
    --We made it here!  We have a valid target..
    local angle = getFiringSolution(obj);
    if angle ~= nil and bot:hasWeapon(weapon) then
        bot:setAngle(angle + math.rad((math.random()-0.5)*20*(1-difficulty)));
        bot:fireWeapon(weapon);
        return(true);
    end
    return(false)
end

function getName()
     return("MOBOT");
end

function gotoPosition(pt)
    if pt ~= nil then
        gotoPositionWasNil = false;
        goalPt = bot:getWaypoint(pt);
      if(goalPt ~= nil) then
         dirToGo = point.angleTo(botPos, goalPt);
        end
    end
end
 
-- Returns the objective for the bot, in the form of a point the bot can navigate towards.
function getObjective()
   local result = nil;
   
   local dest = myPath[soFar];
   gotoPosition(dest);
   
   --Move to next waypoint?
   if (point.distSquared(bot:getPos(), dest) <= 250 and soFar < pathSize) then
      soFar = soFar + 1;
   end
   
    return result;
end

function doObjective()
   --get destination object
   if (soFar ~= 0) then
      local obj = getObjective();
      if obj ~= nil then
         gotoPosition(obj:getPos());
      end
   end
end

function goInDirection()
    bot:setThrust(speed, dirToGo);
end

function onTick(deltaTime)
   -- Since team hasn't been assigned when main runs, I have to do my checking in onTick
   -- Set path if soFor is still 0
   if (soFar == 0) then
      if (bot:getTeamIndex() > 0) then
         if (bot:getPos().y < 0) then
            if (bot:getTeamIndex() == 1) then
               myPath = top1;
            else
               myPath = top2;
            end
         else
            if (bot:getTeamIndex() == 1) then
               myPath = bot1;
            else
               myPath = bot2;
            end
         end
         soFar = 1;
      end
   end

    botPos = bot:getPos();
    assert(bot:getPos() ~= nil);
   
    if (not fireAtObjects()) then
      doObjective();
      goInDirection();
   end
end
You do not have the required permissions to view the files attached to this post.
_
\/
*
*
*
<<

sky_lark

User avatar

Posts: 2053

Joined: Wed Mar 10, 2010 6:00 pm

Post Tue Dec 30, 2014 2:36 am

Re: MoBot

Whoa, neat level! Such a cool concept. I haven't played any MOBAs so I have no idea what the strategy is haha but I seemed to have better luck when I focused on keeping my dudes alive and utilizing their phasers to kill enemy turrets faster. Should be very interesting to try with 1v1.
Follow Bitfighter! FacebookTwitterDiscord
<<

Fordcars

User avatar

Posts: 1016

Joined: Fri Apr 20, 2012 3:51 pm

Location: Some city, somewhere

Post Tue Dec 30, 2014 9:40 am

Re: MoBot

I played with thread last night, it was awesome!
skybax: Why is this health pack following me?
bobdaduck: uh, it likes you.
<<

thread

User avatar

Posts: 36

Joined: Sun Apr 28, 2013 3:37 pm

Location: SPAAAAAACCE!!!!!

Post Tue Dec 30, 2014 10:26 am

Re: MoBot

I find it amazing how fun this little bot makes the level.
_
\/
*
*
*
<<

amgine

Posts: 1399

Joined: Thu Apr 19, 2012 2:57 pm

Post Fri Jan 02, 2015 7:22 pm

Re: MoBot

cool this is fun!
Bitfighter Forever.

Return to Bots

Who is online

Users browsing this forum: No registered users and 1 guest

cron