Here is version 1 of my bot, it beats BasicBattler and rarely NightShade

The choice of ship to shoot at is taken directly from Shooter which is just a function of closeness and health.

The laser firing angle is chosen so that if the enemy continues with the same heading and speed it's a direct hit.

The thruster fires with full power in a direction perpendicular to the laser firing angle to avoid running over own laser. If there is no enemy it fires in the direction of current heading. There is some random direction added to both cases.

Not sure where to upload code so here it is:

**Code:**

-- Cortez the killer.

thrustAngleRange = 3.0

ship = nil

world = nil

constants = nil

function init(shipArg, worldArg)

ship = shipArg

world = worldArg

constants = world:constants()

ship:setName("Cortez_v1")

end

function run(enemyShips)

local thrusterAngle

local laserAngle = fireTheLaser(enemyShips)

if laserAngle then

local angleDiff = (laserAngle - ship:heading()) % (2 * math.pi)

if angleDiff > math.pi then

thrusterAngle = laserAngle + math.pi / 2

else

thrusterAngle = laserAngle - math.pi / 2

end

else

thrusterAngle = ship:heading()

end

fireTheThruster(thrusterAngle)

end

function square(x)

return x * x

end

function fireTheThruster(thrusterAngle)

local thrusterAngleRandom = (math.random() - 0.5) * thrustAngleRange + thrusterAngle

ship:fireThruster(thrusterAngleRandom, 1)

end

function fireTheLaser(enemyShips)

local laserAngle

if (# enemyShips > 0) then

targetShip = getTargetShip(enemyShips)

local xRel = targetShip.x - ship:x()

local yRel = targetShip.y - ship:y()

laserAngle = getAngle(xRel, yRel, targetShip.speed, targetShip.heading)

if laserAngle then

ship:fireLaser(laserAngle)

end

end

return laserAngle

end

function getTargetShip(enemyShips)

local bestRating = math.huge

local targetShip = nil

for i, enemyShip in pairs(enemyShips) do

local rating = enemyShip.energy

* square(ship:x() - enemyShip.x) + square(ship:y() - enemyShip.y)

if (rating < bestRating) then

targetShip = enemyShip

bestRating = rating

end

end

return targetShip

end

function getAngle(xRel, yRel, speed, heading)

local angle

local a = square(constants.LASER_SPEED) - square(speed)

local b = speed * (xRel * math.cos(heading) + yRel * math.sin(heading))

local c = square(xRel) + square(yRel)

local d = square(b) + a * c

if d >= 0 then

local ToF = (b + math.sqrt(d)) / a

local xHitRel = xRel + ToF * speed * math.cos(heading)

local yHitRel = yRel + ToF * speed * math.sin(heading)

angle = math.atan2(yHitRel, xHitRel)

end

return angle

end