
Cells. A massively multi-agent Python programming game. - phreeza
http://phonons.wordpress.com/2010/06/01/cells-a-massively-multi-agent-python-programming-game/
======
ihodes
I got so excited for this that I actually began thinking about writing
interfaces to the game for other languages. It'd be fun to compete in a Lisp
vs Python—maybe one language would lend itself to a certain kind of tribe.

I'll be looking at the source soon, but in the meantime I'm curious to see if
other people would be interested in playing this. There could be a repository
of genomes/tribes you can download and compete against, or perhaps this would
be done server-side so your tribe's genome couldn't be cloned?

As a side note, it seems to me that (unless cells can be aware of their
comrades' positions) global position needs to be availible in order to build
walls, which is damn cool.

Cheers!

~~~
phreeza
Great, I'm glad I'm not the only one that likes the idea! Interoperability to
other languages is definitely on my list for the future, and a kind of ladder-
server, too, where you submit your tribe and it enters into a perpetual
tournament and gets ranked.

~~~
pjdavis
Why stop at a ladder-based tournament system? It would be awesome if we could
have all submissions put into a persistant world and go on until they all die
out. Kind of like a mmorpg for AI robots.

~~~
moconnor
This is what I thought the article was when reading the title. It totally
should be; how hard could it be to hack something together and run it on
appengine?

------
mquander
Recently, since SC2 beta hit, I've been mulling about the idea of a
"programmable RTS" -- an RTS that allows you to preprogram unit AI in some
fashion, and then plays in such a way that your programming really factors
into the game. For example, maybe you have many little units, so that it's
difficult to micro them separately, or maybe the battles operate very quickly,
or your units have an unusually large amount of active abilities.

After all, most of your APM in a game like Starcraft is going toward things
that you could replace with a very small shell script. Although I can't argue
with success, it's always felt silly to me that a big part of the game is just
building enough intuition and reflex so that you can actually spare your mind
to think about the interesting parts. If you can simplify the reflexive pieces
at "game-time" while keeping them interesting in a different way, that might
leave you with a game that's even deeper strategically.

However, it would be a difficult exercise to make an RTS that was dynamic
enough that some folks with a lot of spare time didn't just write "ultimate"
AI for all the units that is close-enough-to-perfect, and distribute that to
all lazy players. Perhaps one might establish limitations on the resources or
length of scripts you can write, so that it's difficult to write a script that
is simultaneously effective for strategy A and different strategy B, and you
need to specialize your code based on your style of play.

~~~
JeffL
Here is a programmable RTS that is a lot of fun:
<http://www.hacker.org/bitbath/>

~~~
mquander
That's really cool. Thanks.

------
swolchok
I've developed an extremely aggressive AI that is able to wipe out mind1 in
about a minute. It's based on mind2 but uses a better algorithm for
exploration, and, when attacked, it calls for help rather excessively.
[http://github.com/swolchok/cells/blob/master/crawling_chaos....](http://github.com/swolchok/cells/blob/master/crawling_chaos.py)

EDIT: my fork also cleans up a couple real issues, including letting the game
run properly when psyco's not installed and allowing the user to specify minds
on the command-line (albeit in a hacky way).

~~~
swolchok
The evolving chaos is able to take out the crawling chaos through improved
colonization behavior and the possibility of developing several disparate
strains. Haven't tried porting the fixed behaviors back to the crawling chaos
and seeing if the "zerg rush" strategy is just better.

[http://github.com/swolchok/cells/blob/master/evolving_chaos....](http://github.com/swolchok/cells/blob/master/evolving_chaos.py)

~~~
icefox
Couldn't resist giving it a try myself and created my own program 'ben'. It
was a good excuse to learn Python. Ended up with a solution that does a good
job and can usually (19/20 times) beat the ones in included in the repo.
Pushed my program up on github: <http://github.com/icefox/cells>

Here is a video (sorry using Quicktime which only grabs the whole screen and
not a window) of evolving_chaos v.s. ben which is fun to watch
<http://www.youtube.com/watch?v=Zy_-4rRmOCc>

~~~
phreeza
That is very nice. Fun to watch. I've included it in the repo.

~~~
swolchok
benvolution makes some tweaks to ben in order to defeat it. :) It does have a
reasonable chance of stalemating, and of getting overwhelmed if the starting
locations are close together.

[http://gitshub.com/swolchok/cells/blob/master/minds/benvolut...](http://gitshub.com/swolchok/cells/blob/master/minds/benvolution.py)

~~~
moconnor
And benmark draws from and defeats both :-)

[http://github.com/markoconnor/cells/blob/master/minds/benmar...](http://github.com/markoconnor/cells/blob/master/minds/benmark.py)

~~~
swolchok
Seems to be identical to ben.py.

~~~
moconnor
Yes, sorry about that. I fessed up my repro when setting up on github.
[http://github.com/markoconnor/cells/blob/master/minds/benmar...](http://github.com/markoconnor/cells/blob/master/minds/benmark.py)
is now the correct version, quite entertaining to watch.

------
mustpax
Really cool. This reminds me of a different "2 algorithms enter 1 algorithm
leaves" type game: <http://en.wikipedia.org/wiki/Core_War> .

Interestingly, Core Wars is from the age of multiple threads running on a
single processor, sharing memory, whereas the more recent Cells represents a
share-nothing distributed system with autonomous agents.

~~~
steveklabnik
I had lots of fun using a variation of Core War called "FukYorBrane," which
used Brainfuck with a few extra instructions. Each program's input tape is the
other's output tape. Tons of fun.

<http://esoteric.voxelperfect.net/wiki/FukYorBrane>

------
CWuestefeld
A zillion years ago (in development years) when MS's .Net platform was new,
there was a platform called Terrarium [1] that was a bit like this. One key
difference was that there was not an explicit means of communication between
bots, so developers figured out a way to semaphore messages by way of simple
movement behavior.

As I searched for a link, I discovered that there's a newer version out just 2
years ago. [2]

[1]
[http://www.devhood.com/tutorials/tutorial_details.aspx?tutor...](http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=323)

[2] <http://terrarium2.codeplex.com/>

~~~
mclin
re: communicating through movement, don't ants and bees actually do this?

It would be cool if you could drop pheremone trails too. I'm thinking like a
programmable Sim Ant

~~~
SIGSEGV
>It would be cool if you could drop pheremone trails too. I'm thinking like a
programmable Sim Ant

That's what ICFP 2004 was. Here's the specification, if you want ideas:

[http://alliance.seas.upenn.edu/~plclub/cgi-
bin/contest/ants....](http://alliance.seas.upenn.edu/~plclub/cgi-
bin/contest/ants.html)

[http://alliance.seas.upenn.edu/~plclub/cgi-
bin/contest/index...](http://alliance.seas.upenn.edu/~plclub/cgi-
bin/contest/index.php)

------
dstorrs
One suggestion: It would be great if cells could pass energy to an adjacent
cell. This would make it possible to form energy pipeling / distribution
systems within your team, and for teams to cooperate meaningfully instead of
simply "fight / ignore". I think this would substantially enrich the game.

~~~
ErrantX
Awesome addition; that would allow making support structures making it a lot
more RTS-like!

------
endtime
This looks awesome...with the exception of "A", every single word in the title
titillates me. Definitely plan to play.

As an aside, to those of you who are interested in this sort of game AI, you
might want to look at the growing (AI sub)field of General Game Playing. The
idea is to write a basic game AI that can take in arbitrary rules, "think"
about them a little, and then play the game against one or more opponents. The
author of the played favored to win this year's championship, Turbo Turtle,
has open-sourced his infrastructure on Google Code (ggp-base), which makes it
orders of magnitude easier to participate. More info:
<http://games.stanford.edu>, <http://cs227b.stanford.edu>.

------
gometro33
An interesting way to keep people interested in the game (during a fight, that
is) would be to allow players to update the AI on the fly.

I'm thinking each player would submit an AI to start the game. At any point
during the game players could "check-in" code (VCS-style) and cells created
from that point on (via the splitting described in the article) would have
this new code. Players would be allow, for instance, 2 check-ins per game. The
upgraded cells would be represented by different shades of the player's color
so that they could be kept track of.

I see this being useful for times when a player drastically misuses his cells
initially or for an entirely different style of play (a different bracket on
the ladder server).

~~~
gridspy
You could try to put into the code the conditions that would cause you to
change your strategy. Then when all those conditions are in place you send a
signal to all cells to change strategy.

Your code then looks at the strategy variable to see which code path to
execute.

------
JeanPierre
Well, considering the message-queue, it should be fully possible to make the
cells into "animals" instead: They mate by randomly picking another cell's
"genome", take 50-50 from each of the cells, and make this the basis for the
new cell.

It would sound like it would be smart to start off with the extremities. Say,
start off with the same amount of 100% agressive and 100% defensive cells.
They mate, get a 50/50-cell, which is partly both. If a combination of 10%
agressive and 90% defensive is "the secret", then the cells will eventually
all become that combination in the end.

Now, the question's whether this is a tactical approach or not...

------
cakeface
Wow I really like this game! My company occasionally does engineering
challenges for fun and I'm going to recommend this for our next one. The last
one we did was competing Robocode (<http://robocode.sourceforge.net/>) bots.
They're written in Java and the game has been around for a while. I'm thinking
that this will be more fun as it is newer and so there's really room to get
creative and have fun.

------
swolchok
Looks like _very_ little attention has been paid to performance in favor of
praying that psyco works on the player's system. I'm avoiding work and I've
forked the project, so watch for a series of little perf tweaks. A few
specific complaints:

Why are you using accessor methods? If it's because you might want to change
them later, you could just use a property if that unlikely event happens.
There is a real cost to accessors in Python. They also add a lot of visual
noise.

Why did you make an enum class (ActionType)? That adds an extra hash table
lookup for not much benefit over

    
    
      ACT_SPAWN, ACT_MOVE, ACT_EAT, ACT_ATTACK, ACT_LIFT, ACT_DROP = range(6)
    

EDIT: the performance seems fine the way it is now. I made some changes but
they didn't perceptibly change the way the game plays. I am grouchy today
because I didn't get enough sleep. Sorry.

~~~
phreeza
Thanks a lot for your comments! Looking forward a lot to your tweeks,
performance will definitely need to be optimized in the future. The problem I
was trying to adress with the accessors and the whole *View concept is that
there are no private members in python, and i was trying to prevent the
minds/genomes from "cheating" by reading data they aren't allowed to. If you
can think of a better way to do that, I'd love to hear from you.

~~~
jerf
Last I knew, the official word is that there is no way to stop Python code
from reading any particular value. Python can even crack into the values
contained in closures if you know the right incantations. If you are looking
to rigidly enforce that only accepted interfaces are being used to read data
in the face of a hostile adversary writing the Python, I believe the current
state-of-the-art is that it is impossible.

If this is a core feature requirement, then as far as I know your only option
is to change languages to something where you can rigidly sandbox. Your
nearest option in programming space would be Perl and some variant of Safe
(that's a CPAN module name). Otherwise, if you can live with a gentleman's
agreement, you're fine. This may make the automatic-online-matchup _really_
tricky, though.

~~~
phreeza
> This may make the automatic-online-matchup really tricky, though.

Another option I was thinking about for this purpose is parsing the python to
make sure they don't get up to anything fishy, but I have no idea how hard a
Python parser would be. My guess is very.

Or we put them into separate proceses, as swolchok suggested.

~~~
jerf
"Another option I was thinking about for this purpose is parsing the python to
make sure they don't get up to anything fishy."

If that was safe, it would have been bundled up into a module. This is a
Frequently Asked Question for Python, and the answer is, you can't.

I thought of process separation, but it won't work. The best performance would
be one persistent process that runs the cell computations, but it's too easy
for Python code to find places to hide data persistently for communication
above and beyond what you expect.

For example, would you have thought to block the following?

    
    
        Python 2.4.3 (...)
        Type "help", ...
        >>> def f():
        ...     f.i = f.i + 1
        ...     print f.i
        ... 
        >>> f.i = 1
        >>> f()
        2
        >>> f()
        3
    

The people who know the most about Python, including the implementors, have
said this impossible. Again, unless someone familiar with the community pops
up and says something has changed in the several years since I was hanging out
on comp.lang.python. But I doubt it.

And mind you, that's _one_ example, and not a very sophisticated one. If
you're answer was "no", or indeed anything other than "duh, of course, I've
known about that for years", then you don't stand a _chance_ at the
sophisticated stuff.

You can't fork at cell-run-time, because while a process couldn't write
anything back out to the parent, it could still grovel over the parent's data
space which could still be used to advantage, and depending on the rest of
your code may still make an out-of-band channel available.

You could fork a process per cell before anything "incriminating" has been
instantiated in the parent process, but that's got a lot of problems even on
one machine (including the 32K process limit), let alone a hosted service, and
you'd still end up with the possibility of a "cell history" being recorded
that could be potentially exploited.

Python does not give you the necessary primitives to accomplish this task. I
see three options: Live with it (a viable option except online), spawn one
process per team and officially bless that level of communication (though it
radically changes the nature of the game), or change languages.

To be honest, Python is going to cause you other problems on your online
server too, such as the extreme difficulty you're going to face in isolating
Python functions to a certain amount of CPU time. (Same problem, as long as
the Python code cooperates it might be possible (and it might not really) but
if it starts hostilely modifying the parent code you lose.) Other languages
have support for that too.

Unfortunately, you're _really_ bashing on Python's weaknesses here.

~~~
swolchok
> You can't fork at cell-run-time, because while a process couldn't write
> anything back out to the parent, it could still grovel over the parent's
> data space which could still be used to advantage, and depending on the rest
> of your code may still make an out-of-band channel available.

Forking _and execing_ prevents this.

~~~
jerf
"Forking _and execing_ prevents this."

And will be uselessly slow, which is why I dismissed it with hardly any
thought.

    
    
         # time bash -c "for i in {1..1000}; do python -c '1'; done"
    
         real    0m9.351s
         user    0m6.439s
         sys     0m2.868s
    

No way will that be acceptable, and that's before we even load any of the cell
code in.

------
cmelbye
Has anyone with a Mac been able to install pygame to run this? From what I'm
reading, it seems like a complicated process. Could someone throw together a
small guide?

~~~
ihodes
I've spent an hour or so trying to get pygame working on OS 10.6. I'm using
Python 2.6.1, though I've tried it with 2.5 and 3 as well.

I've tried their binaries, their source (including using the SDL.Framework
which was suggesting in the SuperUser link another commenter posted.)

If someone would like to port this to something a little more usable, I'd be
obliged. If not, I'll be spending a bit of late June doing that.

~~~
cmelbye
The superuser link worked perfectly for me. I wonder if we could do some sort
of py2app type thing.

~~~
ihodes
I'm looking into porting the whole graphically-related portion of the code
into pure OpenGL, which should be just about as easy as it gets to ensure
cross-platform/computer consistency.

~~~
infinite8s
Take a look at pyglet: <http://pyglet.org>

------
jashmenn
I wonder how well this would work in real-time over the web. We could
establish an API and let everyone hack in whatever language they please.

Here is a short list of open-source MMO servers we could start with:
<http://www.reddwarfserver.org/> <http://opensimulator.org/wiki/Main_Page>
<http://www.next-gen.cc/>

------
Sthorpe
I have dreamt about this for years. I want to rent out a big warehouse and get
a bunch of artists and programmers together to create/play a game like this.
And then everyone just watches (like a movie) at the end.

I would WAY rather do this than go to a movie or play videogames. I mean think
of all the programming you would learn and get good at. After playing video
games I just feel tired and my fingers hurt.

Let me know if anyone wants to help me organize something like this.

------
gometro33
Sounds like a good game to test out with Intel's new "Knights Corner" chip!

<http://news.ycombinator.com/item?id=1395513>

One cell per core? Ah, the future...

------
phreeza
I've created 2 mailing lists for people to keep in touch.

<http://groups.google.com/group/cells-game-users>
<http://groups.google.com/group/cells-game-devs>

------
sidmitra
For people who like this, i would point you to the first such game i played -

<http://www.corewars.org/>

~~~
phreeza
I used to play a programming game, probably should have mentioned that in the
article. It was called AT-Bots, and was a lot of fun. Never quite got my head
around corewars though.

------
akkartik
Related: <http://github.com/ryanb/ruby-warrior>

I built a bot for it once: <http://github.com/akkartik/brooks-ruby-warrior>

------
NathanKP
I'd really like to see a video of this game in action.

~~~
phreeza
Good idea actually, I'll make one and include it with the next post. It is
really quite fun to watch. In the mean time, just pull it from github and give
it a spin.

------
prosa
Put your email in your profile! :)

I bet I'm not the only one who's excited and would love to contact you about
this!

~~~
phreeza
Done!

Edit: even better to contact me through github though.

------
mleonhard
This is similar to a simulation I wrote 3 years ago, called Bluedogs. Bluedogs
creates the genomes randomly. It's C++ and SDL and runs on Linux and Windows:

<http://tamale.net/bluedogs/>

------
jayro
Wow, this is very similar to the game idea I describe in Techzing 40 –
AppIgnite Revealed: <http://techzinglive.com/?p=194>.

------
jcl
It might be fun if there were a way for humans to control a colony, so that
humans could try to compete against purely algorithmic players.

------
SingAlong
I was wondering how the audience would take this. I'm so excited to see such a
project on top of HN. I'm building a _geeky_ game too (not similar to this).

What do you people think about such games being made commercially? (indie
ofcourse)

------
jules
RoboCom! The fun thing about RoboCom is that bots don't fight. Instead they
write to each others memory, causing the other bot to run the program you want
(like a virus). This results in very interesting strategies.

------
RiderOfGiraffes
Someone could create a "King of the Hill" system, similar to the one here:

<http://www.gamerz.net/c++robots/>

I've got a robot "on the hill" and it's great fun.

------
chuhnk
I am interested in this game simply to learn python. It's always the projects
that inspire and excite you in which you make the greatest gains.

~~~
phreeza
It would be a good way to do that, I'm sure. I actually learned some of my
early programming on a programming game called AT-Bots, where you had to write
some kind of assembler-like code.

------
nfriedly
This reminds me of MIT's BattleCode tournament - <http://battlecode.mit.edu/>

------
wilshire461
Cool game but was it the intent to have an unlimited supply of food at each
node? It seems like this could be abused quite badly.

------
Alleyfield
So... Basically "cells" is nothing more than a sophisticated version of John
Convay's _Game of Life_? <http://en.wikipedia.org/wiki/Conways_Game_of_Life>

~~~
Alleyfield
Why the down vote? Is someone trying to imply that Cells isn't a sophisticated
version of the Game of Life?

I might be blunt, but I'm not trying to be rude on purpose

~~~
gloob
_Is someone trying to imply that Cells isn't a sophisticated version of the
Game of Life?_

Yes.

------
drlisp
wow!

