BerryBots forums

It is currently Sat Nov 27, 2021 3:24 am

All times are UTC

Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Sep 23, 2015 12:31 pm 

Joined: Wed Sep 23, 2015 12:17 pm
Posts: 22
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").



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...

PostPosted: Wed Sep 23, 2015 6:00 pm 
Site Admin
User avatar

Joined: Sat Nov 17, 2012 5:03 am
Posts: 88
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.

PostPosted: Wed Sep 23, 2015 7:26 pm 

Joined: Wed Sep 23, 2015 12:17 pm
Posts: 22
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.

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


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
   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())
      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:fireTorpedo(firingAngle, targetDistance)

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
   if ship:speed() >= 0.5 or distance >= 0.5 then
      ship:fireThruster(aang, amag)
      arrived = 1
      ship:fireThruster(ship:heading() + math.pi,ship:speed())

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

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 ;).

PostPosted: Mon Nov 16, 2015 5:52 am 

Joined: Fri Nov 13, 2015 12:38 am
Posts: 18
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!

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

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

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

-- 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)

-- 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)

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

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

PostPosted: Thu Jun 20, 2019 7:37 pm 

Joined: Wed Sep 23, 2015 12:17 pm
Posts: 22
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.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group