BerryBots forums
http://berrybots.com/forum/

More sophisticated available bots to test own bots
http://berrybots.com/forum/viewtopic.php?f=1&t=443543
Page 1 of 1

Author:  sadd [ Wed Sep 23, 2015 12:31 pm ]
Post subject:  More sophisticated available bots to test own bots

Hello fellow Berryboters/Berries/whatever :),

I just stumbled upon berry bots a couple of days ago and decided to try it yesterday evening and I have to say I'm enjoying it quite a lot for a lot of different reasons... Nice work on the development.

However, I feel like I'm already beating the standard/sample bots fairly easily with my first bot, and thus I was wondering if there are any more sophisticated bots available to test my bots against them. I would prefer if it was in something like the online playberrybots so I can't just peak at the source code of the enemy (I do have my weak/too curious moments ;) ). I'm mainly interested in the more standard battle scenarios (like "battle1" or "empty").

Cheers

Sadd

EDIT: I found at least one bot on the forum by now. But I feel there should be some kind of official database/repository. One even could run automated battles on the database to identify the best bots...

Author:  Voidious [ Wed Sep 23, 2015 6:00 pm ]
Post subject:  Re: More sophisticated available bots to test own bots

Hey and welcome! Great to see some activity here. :-) Glad you're enjoying it!

My original thought was people would put their bots on the wiki (Category: Bots), but then people just posted them to the forums. I'd be happy to add some stronger bots in the web UI, I'll do that soon. NightShade is probably my favorite bot, but it's kinda slow, so not a great candidate for the web UI. But the rest are all pretty quick. And maybe I'll go through and make wiki pages for the bots that have been posted here so that could serve as a central collection.

I have run all the bots against each other locally using the simpletourney Game Runner - Frohman's Sanic is definitely the strongest existing bot. I also have a new stage in mind that would include some stronger bots, but it will probably wait until I get the next version of the app out the door.

Author:  sadd [ Wed Sep 23, 2015 7:26 pm ]
Post subject:  Re: More sophisticated available bots to test own bots

Thanks for the answer.

I checked out the other bots and gonna try to beat them consistently. My first-evening-bot "Mark I" isn't performing terrible though against them (mainly in "empty", "battle1" is okay though as well). Here's the code for anyone to check out.

Code:
-- Mark I.


ship = nil
world = nil
width = nil
height = nil
approaching = 0
arrived = 0

function init(shipIn, worldIn)
   
   ship = shipIn
   world = worldIn

   width = world:width()
    height = world:height()
   
   ship:setName("Mark I")
   
   approaching = 1
   arrived = 1

end

xdes = 0
ydes = 0
function run(enemyShips, sensors)

   if approaching == 1 or (# sensors:hitByLaserEvents() > 0) or ship:hitWall() then
      xdes = math.random() * width
      ydes = math.random() * height
      approaching = 0
   end
   shipMoveTo(ship, xdes, ydes)

   if (# enemyShips > 0) then
      local targetShip = enemyShips[math.floor(math.random() * (# enemyShips)) + 1]
      local targetDistance = calcDistance(targetShip.x, targetShip.y, ship:x(), ship:y())
      local projTargetDistance = targetDistance
      for i=1,10,1 do
         projTargetDistance = calcDistance(targetShip.x + math.cos(targetShip.heading)*targetShip.speed*projTargetDistance/25,
                                    targetShip.y + math.sin(targetShip.heading)*targetShip.speed*projTargetDistance/25,
                                    ship:x(), ship:y())
      end
      local firingAngle = math.atan2(targetShip.y - ship:y(), targetShip.x - ship:x())
      local projFiringAngle = math.atan2(targetShip.y + math.sin(targetShip.heading)*targetShip.speed*projTargetDistance/25 - ship:y(),
                                 targetShip.x + math.cos(targetShip.heading)*targetShip.speed*projTargetDistance/25 - ship:x())
      ship:fireLaser(projFiringAngle)
      ship:fireTorpedo(firingAngle, targetDistance)
    end
end

c1 = 1.
c2 = 1.

function shipMoveTo(ship, x, y)
   local angle = math.atan2(y - ship:y(), x - ship:x())
   local distance = math.sqrt((y - ship:y())^2 + (x - ship:x())^2)
   local ax = c1*math.sqrt(distance)*math.cos(angle) - c2*ship:speed()*math.cos(ship:heading())
   local ay = c1*math.sqrt(distance)*math.sin(angle) - c2*ship:speed()*math.sin(ship:heading())
   local amag = math.sqrt(ax^2 + ay^2)
   local aang = math.atan2(ay, ax)
   local alim = math.max(amag,1.)
   ax = ax / alim
   ay = ay / alim
   amag = amag / alim

   if distance/ship:speed() < 10 then
      approaching = 1
   end
   
   if ship:speed() >= 0.5 or distance >= 0.5 then
      ship:fireThruster(aang, amag)
   else
      arrived = 1
      ship:fireThruster(ship:heading() + math.pi,ship:speed())
   end
end

function calcDistance(x1, y1, x2, y2)
   return math.sqrt((y1 - y2)^2 + (x1 - x2)^2)
end


Code is very messy and some obvious flaws (like taking the projectile speed 25 for both laser and torpedoes) I fixed in my current working bot are in there as well. Next versions are going to be more sophisticated for sure ;).

EDIT: At some point I'm gonna upload some bots to the wiki like you intended. The proper next versions though ;).

Author:  Croug [ Mon Nov 16, 2015 5:52 am ]
Post subject:  Re: More sophisticated available bots to test own bots

So I noticed your bot could use a little cleaning up, one way I like to do this is to copy and paste a few utility functions below my robot to avoid having to manually do these algorithms in my code. Here are the ones I use, hope they can help you out!

Code:
-- Utility Functions --
LASER = 25 -- Speed of a laser shot (distance/tick)
TORPEDO = 12 -- Speed of a torpedo shot (distance/tick)

-- Generate random location
function randomLoc()
   dest = { }
   dest.x = math.random() * world:width()
   dest.y = math.random() * world:height()
   return dest
end

-- Rotate first point (tx, ty) around second point (ox, oy) a specified angle (angle) in radians
function rotate(tx, ty, angle, ox, oy)
   local s = math.sin(angle)
   local c = math.cos(angle)
   
   tx = tx - ox
   ty = ty - oy
   
   local xnew = tx * c - ty * s
   local ynew = tx * s + ty * c
   
   local target = { }
   target.x = xnew + ox
   target.y = ynew + oy
   
   return target;
end

-- Returns length of a table
function tableLength(T)
  local count = 0
  for _ in pairs(T) do count = count + 1 end
  return count
end

-- Returns distance between two points (x1, y1) and (x2, y2)
function distance(x1, y1, x2, y2)
   local op = math.pow(x2 - x1, 2)
   local ad = math.pow(y2 - y1, 2)
   local ab = math.abs(op + ad)
   return math.sqrt(ab)
end

-- Returns the angle (in radians) between two points (x1, y1) and (x2, y2)
function getBearing(x1, y1, x2, y2)
   return math.atan2(y2 - y1, x2 - x1)
end

-- Converts a radian angle to degrees
function toRadians(angle)
   return angle * (math.pi/180)
end

-- Converts a degree angle to radians
function toDegrees(angle)
   return angle * (180/math.pi)
end

Author:  sadd [ Thu Jun 20, 2019 7:37 pm ]
Post subject:  Re: More sophisticated available bots to test own bots

The link to Sanic in the wiki is down (it's a dropbox link) btw, and I'm again looking for bots to battle against and learn from... If anyone can post Sanic here, I think just as text would be best for preservation.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/