Bots/AI Added into a game

Can anyone share at least some simple bots i can add into a game? If needed, i can provide the game, which is 3-D. Advanced route solving botswould be better, but ill take any kind.

I have very simple bots in my first game ‘pushball’. But probably too simple for you.

Any bots will be appreciated

This is a bit of a complex question. I have several games that do some “botting” that would be of use but the real issue is understanding how they do what they do.

Your best bet is to make a generic Enemy class that does generic stuff: move, fire, think. Then make classes that extend the generic Enemy class to do specific things, such as fire at a rate, or move based on logic. YOU HAVE TO DECIDE THAT LOGIC, so a “bot” isn’t really helpful as a request as only you know the logic.

For example, in Cofender, all enemy ships have some intelligence to fire at the player, but a specific ship (the saucer) intentionally tries to sit under the player instead of impacting them so that it can fire bullets and stay alive. This logic is in the Saucer class. The Aliens try to fire at the player at some intervals and stupidly move along the bottom of the screen looking for a human to pick up. Once they do, they go straight into the air. That logic is in the Alien class. Both inhereit from the Enemy class, which has a Heartbeat() function. This Heartbeat() function is called by the generic Codea draw() call.

Could you link me to one of those classes to add logic too?

Example Attacker class…
Everything that this class can do is in Heartbeat().

--
-- Attacker.lua
--
Attacker = class()
--class used to attack the player. Invader and others should subclass/extend this.


function Attacker:init(params)
    assert (params.name, "Enemies must have a name for indexing")    
    self.name = params.name
    self.pos = params.pos or vec2(0,0)
    self.speed = params.speed or 1            --movement speed
    self.direction = 1 --or -1
   --other generic stuff here     
end

function Attacker:Heartbeat()
    self:Move()
    self:Shoot()
    self:CheckForImpact()
    self:draw()
end

function Attacker:Move()
        local delta =  (worldpos + player.screenpos) - self.pos
        delta = delta:normalize()
        self.pos.x = self.pos.x + (delta.x) * self.speed
        self.pos.y = self.pos.y + (delta.y) * self.speed
        self.cycles = 120 -- once every 2 seconds, codes is about 60 cycles ps
        --something custom here...
        --self.pos = CorrectPosition(self.pos)
end

function Attacker:draw()

    --sprite(self.img, self.pos.x-worldpos.x, self.pos.y)
    --sprite(self.img, 10000+self.pos.x-worldpos.x, self.pos.y)
    -- Use meshes, MUCH FASTER    
    self.d.pos = vec2(self.pos.x-worldpos.x, self.pos.y)
    self.d:draw()
end

function Attacker:touched(touch)
    -- Codea does not automatically call this method
end


function Attacker:Shoot()
    
    self.cycles = self.cycles - 1
    if self.cycles < 1 then
        --call only once or else you get homing bullets!
        local vector =  (worldpos + player.screenpos) - self.pos
        vector = vector:normalize()
        local dist = self.pos:dist(player.screenpos + worldpos)
        if (dist< 1200 and dist > 20) then  --don't fire if TOO close! Stray bullets!
            self.cycles = self.maxCycles       --again. should make a CONST
            sound(DATA, "ZgNAJwBDE1xPITlPiEBdPW8lCD8AAAAARQBifzRAOFQiGloU")
------ Cofender has a bullet class for firing...
            b = Bullet({ 
                pos = vec2(self.pos.x, self.pos.y), 
                name = "Bullet"..tostring(math.random(1000)), 
                vector = vector , damage = self.damage,
                impactDamage = self.impactDamage,
                speed = self.FireSpeed
                })
                table.insert(bullets, b)  --which are in a game table.
        end
    end
end


function Attacker:CheckForImpact()
    local rbx = self.pos.x - player.width
    local rax = self.pos.x + player.width
            
    local rby = self.pos.y - player.height
    local ray = self.pos.y + player.height
            
    if (rbx < player.screenpos.x+worldpos.x and rax > player.screenpos.x+worldpos.x and 
        rby < player.screenpos.y and ray > player.screenpos.y) then 
        player:IsHit(self.impactDamage)  --damage player...
        self:IsHit(player.shields)        --player impact damages this thing, too!        
        RemoveEnemy(self.name) 
    end
end


function Attacker:IsHit(damage)
    --shot
    self.health = self.health - damage
    sound(SOUND_HIT, 8780)
    sound(DATA, "ZgNADgJBQkFHQ0BAAAAAAMK++z4tmeg9NABAf0JAQEAVO0BB", .2)

end

AutoGist link to Cofender is in this location:
http://www.twolivesleft.com/Codea/Talk/discussion/1971/cofender-a-game-inspired-by-defender/p1