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.
I'd certainly be interested in playing this, especially online. I'm envisioning a system where you upload your genome, and the system automatically puts it in battles against a random selection of others. Some sort of ranking algorithm is used to create a leaderboard. You can also choose to watch a battle between any two or more genomes you like. To avoid gaming the scoreboard that would probably need to not count towards their score, or only once a day or something.
>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.
I don't think so. All global position tells you is "how far away are the boundaries of the map?" Unless there's something I'm missing, you can get everything else just by keeping track of "offset from where I started".
As another side note, restricting messages to integers seems pointless, since arbitrary information can be uniquely encoded as an integer given enough ingenuity. It's a problem that would get solved once and then just irritates people instead of actually constraining solutions. (I assume python integers are only bounded by available memory space.)
Limiting them to n-bit integers, where n = 4 or 8 for example, would be more pointful, but again I think it would probably only make a particular behaviour harder to implement, not significantly limit the set of behaviours that are possible to implement.
I'd rather see communication restricted to nearby cells, but possibly a way to leave messages in place (like ants do with pheromones). This would require cells to be a bit more autonomous, and would prevent information from propagating instantaneously. As we can see from real-world ants, this doesn't preclude cooperation, but does make it a bit harder.
A way I thought might be feasible is having the actual games run on servers and then dump the game logs in a simple format, so they can be played back with either the original game or any kind of player people come up with, eg browser-based.
Concerning the integer vs bit, that was what I meant, was still thinking in terms of C ints. An even more extreme version would be to force the agents to store their state in a similar manner, but I think that would be taking it too far.
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.
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.
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?
I just noticed that your git repo hasn't been updated since late 2009–are their updates to this project that just haven't been posted yet? Perrrrhaps with additional comments that might make it easier if one wanted to contribute?
> ladder-server, too, where you submit your tribe and it
> enters into a perpetual tournament and gets ranked
That would be too cool. I'd love to see this happen. I wonder what kind of market there is for something like this.
EDIT: I'm going to be looking through the code more today, though right now I am going through finals at college. I don't want to promise anything, but this is something I could see myself contributing to, if you'd want (though now might not be the time so early in the process). Shoot me an email (in profile), if you'd like to be in touch.
The code I have in github is pretty much identical to what I describe in the article.
Documentation is nonexistent, sorry for that. That was the first thing that came to mind when I saw that this hit the front page, should have thought of that earlier.
I'll go through and comment it though, this resonance has given me a big boost in motivation.
I also think this project is really interesting (which is why I'm following it and some of the forks).
May I recommend Microsoft's TrueSkill algorithm for ranking genomes? There's C#[1] and Java[2] implementations available. Full disclosure, I have no association with Microsoft Research, but I am the author of JSkills.
EDIT (because for some reason my only option is reply): The other cool thing about TrueSkill is that it can handle multiple players on multiple teams. So, if anyone decides to add the capability for 1v1v1, 1v2, 1v1v2, etc, TrueSkill is ready.
It'd be fun to compete in a Lisp vs Python—maybe one language would lend itself to a certain kind of tribe.
Lisp vs. Python would be most interesting if cells could pass arbitrary information to each other. This would make it easy for Lisp cells to modify their own code. Cells signalling each other and querying each other's information would enable interesting interactions. Some sort of sand boxing would seem to be desirable.
Show me how you would write self-modifying code in Lisp and I'll be happy to show you the analog. Replacing functions at runtime in Python is just as easy as replacing them at runtime in Lisp.
Ah, you might be setting yourself up for a fall there :) one of Lisp's key elements if the ability to be self modifying (a large amount of Lisp code you will see is self-modifying) to an extraordinary degree.
Python doesn't even begin to match it's abilities in this arena.
For example one thing Python is currently unable to do is modify a line in a function to do something completely arbitrary (well, theoretically you could code a specific line to be able to do that, but it wouldn't be trivial to make an entire function that could be trivially modified on the fly).
Macros have nothing to do with self-modifying code. You clearly have no idea what you're talking about. Macros are compile-time transformations of code: they have no runtime effect whatsoever.
> The code examples on there are fairly simple though (but it starts you in the right direction).
Dude, I've got PG's ANSI Common Lisp on my bookshelf and I've read On Lisp multiple times. I understand macros. What I don't understand is this Lisp worship evinced by people who actually have no idea what they're talking about with respect to self-modifying code.
> For example one thing Python is currently unable to do is modify a line in a function to do something completely arbitrary (well, theoretically you could code a specific line to be able to do that, but it wouldn't be trivial to make an entire function that could be trivially modified on the fly).
Provide a Lisp example of "modifying a line in a function" that runs in SBCL and I'll show you the same code in Python. Seriously: you're the one making a claim here, you need to be backing it up.
P.S. I remain utterly unimpressed by the anonymous coward downmodding me, upmodding you, but clearly either unwilling or (more likely) unable to defend your claim. More semi-religious Lisp fanaticism <yawn>.
I apologise... the last reply I kinda retract, as you say - it was a bit silly.
I have to admit your posts came across as the old "My Language is As Good As Yours" argument, but it appears your a Lisper too? I have to also admit everything I have seen/heard says Lisp is the original self-modifying language and is damn good at it :) but in retrospect that wasn't the point you were making.
(I was hoping a Lisper would step in with some code... but apparently not...)
> I apologise... the last reply I kinda retract, as you say - it was a bit silly.
Thanks, I appreciate that.
> I have to admit your posts came across as the old "My Language is As Good As Yours" argument, but it appears your a Lisper too?
I'm well-versed in Lisp, but I don't typically choose it for personal or professional tasks for a number of reasons.
> I have to also admit everything I have seen/heard says Lisp is the original self-modifying language and is damn good at it :)
The original self-modifying code was assembly language (or, really, machine code). It's a useful trick when you're working with extremely constrained computers whose memories are measured in single digit kilobytes, but long ago was recognized as really difficult to use in writing quality software. Real self-modifying code, which means code that actually overwrites the instructions the processor will execute, makes it incredibly hard to reason about programs and debug the resulting software. Real self-modifying code was long ago relegated to the likes of Mel (<http://www.cs.utah.edu/~elb/folklore/mel.html>). As I understand it, most Lisp programmers simply mean that their system properly handles the replacement of most (all?) functions/methods/definitions at runtime, which is in large part true of Python as well.
I open to being corrected by a Lisp programmer using a modern Lisp (hence my request for SBCL) to show an example of real self-modifying code, but I really don't expect that any will, because I don't think anyone's seriously written such code since I was out of elementary school.
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.
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....
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).
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.
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
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.
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.
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.
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]
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.
It's possible (albeit slowly and indirectly) if you have enough energy to spawn, because dead cells always drop 25 energy. (They take 50 energy from their creator and start with 25 energy, so spawning doesn't create extra.)
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.
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).
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.
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...
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.
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
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.
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.
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.
> 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.
"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?
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.
> 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.
Thanks for that, sounds like you really know what you are talking about.
Probably for now the best solution would be to make this form of cheating a bit hard, and then living with it, and having provisions on the ladder server to erase all scores based on a cheating genome if it is detected.
That will get you a long way, certainly. Obviously I'm only referring to a perfect technical solution being impossible; social solutions are very feasible. Getting crap past an automated detector is easy, however most of it will also be readily visible to human eyes.
And given that you are willing to live with that, Python is otherwise a pretty good language, very easy to pick up, etc. I love this in general, I'm explaining this so you don't end up burning time in a tarpit and instead use it to build something that will actually work. :)
After some thought, I agree with your assessment. You could set up a server to make people mostly play nice, but in the current stage of development, a gentleman's agreement is probably the right choice.
If you sandboxed the Python process running agent code to limit the mischief to that particular process, that would go a pretty long way, and that sort of thing is certainly possible by restricting syscalls at the OS level.
Would writing the actual simulator in C and running the python code for the cells from there be a good option in your opinion? That would make integration of other languages a lot easier, too.
Is this true of all implementations? I know CPython and PyPy have this limitation, but might it be possible to make something work in IronPython, Jython, or some other project I'm as yet unaware of?
Is this ready for primetime? The documentation I found on it seems a bit tentative to me, but it may simply have not been updated. It is worth pursuing if so. Combined with standard OS limitation mechanisms, which I would certainly use in addition to this, it might at least be worth a try.
I would wait to say PyPy has "perfect" sandboxing until it has been attacked for a while, though. CPython used to have a sandbox module, too. But at least PyPy has been designed with this use case in mind.
PyPy's sandboxing hasn't been as thoroughly analyzed and tested as, say, Javascript's (not by far) or Java's, but the actual construction is simpler and arguably better. The PyPy devs, at least, are fairly convinced of its robustness. Basically they whitelist system calls and all other calls are translated to sandboxed calls during compilation of the sandboxed interpreter, as I recall. This is entirely different from CPython's restricted execution, which was essentially a blacklist of Python calls/attributes-- every attempt at such a system has died a death of a thousand cuts; it really pays to do it from the bottom up like PyPy or E.
It might not be ready for prime-time in some very critical systems (like a web browser for example) but it's honestly probably good enough for this, especially in combination with process jailing as you suggest. I might consider trying to patch Cells up to use PyPy's sandbox instead of the non-solution currently implemented (I cried (okay, groaned) when I heard about it-- yeagh), when I have time, and if nobody else does it first. I'm a bit worried anything I write now would get lost or broken in the incoming tide of patches/changes anyway.
The main problems with using PyPy's sandboxing is probably with communication to/out of the sandbox, which is apparently problematic. I also anticipate some complaints about relying on PyPy in the first place, which is rather abnormal compared to using CPython-- using and relying on PyPy-specific features is pretty much unheard of.
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?
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.
I installed python 2.6 from python.org, and then installed the development build of pygame from http://thorbrian.com/pygame/builds.php, and it works fine. (I'm running OS X 10.6.3)
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.
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.
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.
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:
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)
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.
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.
It does take some inspiration from the game of life, but if you look closer, the similarity is more visual than anything else. The relation to and foraging simulations is a lot closer.
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!