jump to navigation

Bacteria and Bots June 10, 2008

Posted by blueapple in Boteria.

Ah, yet another lame attempt to make a cool name: Bot + Bacteria = Boteria.

This project started to grow in my head a couple of weeks ago. I’ve always enjoyed playing various “programming games”; which are games that allow the programmer (gamer) to write an A.I. and then watch it fight other programmers’ A.I.s.

A programming game is a computer game where the player has no direct influence on the course of the game. Instead, a computer program or script is written in some domain-specific programming language in order to control the actions of the characters (usually robots, tanks or bacteria), which seek to destroy each other.

Wikipedia: Programming Game

My favorite has become Grobots (Pronounced “grow-bots”). It is described as

[..] a game in which robots eat, fight, and reproduce under the control of programs written by the players.”

And that is basically what’s to it. The fascinating thing about it is the complexity of the A.I. that can be written. Take for example the side Flower by Tyson Hoffman. It tries to position it’s cells in the shape of a flower and quoting Hoffman:

It [Flower] forms rings, which grow from the center this means the outside can be damaged, but still have a viable center.

Here’s a picture of it:

If you want to have a look at it’s source code, check out Hoffman’s wiki, located here.

It is sad to see that the popularity of Grobots has declined a lot, though. I believe it is partly because of the scripting language used. It is an implementation of the language Forth. The more popular games use C-like languages (Robocode – Java, Robot Battle – Mix of Basic, C and JavaScript).

Although, the concept of Grobots beats all the “robot-on-robot” type of games with horselenghts, the language makes it unattractive. So I decided to give it a shot: mixing the concept of Grobots with a more inviting scripting language.

What language to use then?
The choice stood between Python, Lua, GameMonkey, AngelScript and creating my own.

Creating my own would take ages and would not be even close to what the other mentioned has to offer.

AngelScript and GameMonkey both use a C-like syntax, while Python and Lua have a more BASIC-like (atleast Lua).

Lua and Python are big and well-known, they have been proven to work numerous times, both by amateurs and professionals. GameMonkey and AngelScript on the other hand are relatively small, compared to Lua and Python, and are not as widely spread.

I went for Lua. Why? I did already have some experience with it and the others just didn’t work the way I wanted them to when I tried them. A big tip if you choose to use Lua in a project is to checkout the LuaBind project which makes the process of binding C++ (classes etc.) to Lua a breeze in comparison to doing it without.

Now, after a few evenings (and nights) I’ve got bots flying around, following and bouncing of each other.

The blue circles are “sensor shots” which are used by the bot to get a list of objects in range.

This is what an update function can look like at the moment.

last_sensor = 0
last_seen = 0
e_id = -1

function update(me)
    if e_id == -1 then
        if me:getTime() - last_sensor > 30 then -- Scan for a target every 30:th update
            bots = me:useSensors(0.5)
            last_sensor = me:getTime()

            if bots:getSize() > 0 then -- There was a bot in range
                e_id = bots:getAt(0):getID()
        if math.mod(me:getTime(), 3) == 0 then -- Use the sensors every third update
            bots = me:useSensors(1) -- Full strenght (0..1)

            if bots:getSize() > 0 then
                i = 0
                while (i  60 then -- It's been more than 60 updates
                e_id = -1                                   -- since we last saw the target,
                me:setEnginePower(0)                  -- let's find a new one.

Now that I see it, it looks almost more unattractive than Grobots’ code.

But step through it line by line, it is quite logical after all and this is after only a few days of work (Things will change, it is by no means final).

As always, here is a video:


The two bigger bots use the A.I. posted above, notice how they get stationary when they lose their target (e_id = -1). And also, I disable the drawing of sensors in the middle of the video.

We’ll see where this leads. (Skynet anyone?)



1. Program Language - June 10, 2008

Ultimately, no one cares what language you use while your program works. Program Language

2. blueapple - June 10, 2008

Well, normally, no.

But in this case, where the language is the interface between the game and the gamer, I believe it actually does make a difference.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: