Tuesday, May 29, 2007

Emergent Behavior

Like many programmers I find working with artificial intelligence fascinating. Most of my next several post will discuss common AI topics; and of course I'll provide source files.

The focus of my first two or three AI posts will be on emergent behavior. Some AI is very complicated (think deep blue here). But what I think is extremely cool is when you have a simple set of rules and get a lot of interesting behavior out of it.

Emergent behavior can be described as behavior that isn't explicitly defined by the system or by any rule in the system, but still occurs. Well, that's my definition anyway :). Think of a line of ants walking across a yard. No ant knows how long the line is, or even that its a line. The ant just follows a scent or taste and the emergent behavior is dozens of ants following what looks like a long organized line.

I love emergent behavior! From a programmatic standpoint here is generally how it works.
  • Your system supports at least 1 agent type. An agent is anything that you want to follow a set of rules. Such as an ant, bird, monster, etc.
  • Each interval you apply the rule set to each agent.

That's it! Well, the devil is in the details. Applying the rule set of course depends on the rules. Luckily this is usually not too complicated.

As an example of emergent behavior I've created a Conway's Game of Life example (below). This is a very simple example. In this case, there is a larges grid of agents. There are around 2,000. The agents cannot change positions. Each agent is either alive or dead.

Every iteration these simple rules are applied to every agent.

  • A lonely agent dies. So, if it has two or fewer living neighbors then it dies.
  • An overcrowded agent dies. If the agent has greater than 3 living neighbors then it dies.
  • A content agent lives. If the agent has 2 or 3 neighbors then it lives.
  • Resurrection. A dead agent with exactly three neighbors is given life.

As you can see, the rule set is simple. But when applied to every agent you get some interesting behavior. Check it out below. Read even further to learn about some seed patterns.

DOWNLOAD




The Game Of Life is a well known system. Certain seed patterns have been found that end up exhibiting certain features. For instance, a 'spaceship' is a pattern that moves itself across the board. In the example above I show two such examples - glider and light weight spaceship. The 'diehard' example is a pattern that looks interesting and dies after 130 generations.

So, is this useful at all? Not really. Or at least not to me. The Game of Life isn't something you can just take and use in a useful way (or if you can then please clue me in). It is generally just used as a simple example of emergent behavior.

The next example I'll show in a day or so is more useful, and way cooler!

1 comments:

matt zb said...

Hi Jobe,

I did some experiments with the Game of Life and other cellular automata a few months back, mainly in the name of exploring some ideas of Universal Automatism, a philosophy that has a lot to do with emergent behaviour.

Your angle is game development, which may not have obvious applications for GOL, but I do think it is a rich area for exploration and something I'm still thinking about a lot. AS3 has now unlocked a lot of heavy maths potential for Flash.

I did make a cool bit of abstract art using GOL though, see here

Matt