11,641,209 members (64,254 online)

# AI: Dawkins Biomorphs / And Other Evolving Creatures

, 29 Jan 2007 CPOL 101.4K 525 53
 Rate this:
An implementation of Dawkins Biomorphs and some more crazy evolving creatures.

## Introduction

A while ago, I found something entitled Biomorphs, which appeared to be a bunch of random drawings created by some sort of computer program. I began investigating this a bit further, and found out this was actually the result of running a popular AI type program, which is carrying out an algorithm described by Richard Dawkins from his "The Blind Watchman" book, entitled BIOMORPHS.

Dawkins investigated the possibilities inherent in just the combination of mutation and selection, when combined with a very powerful development (decoding) process.

This is basically a recursive algorithm that has some genes and uses some mutation and some random selection. That's it. That is all that is required to produce a wide variety of fascinating virtual creatures, some which look very genetic.

## Dawkins Basic System

The phenotypes (how it looks) in Dawkins system were essentially branching tree structures. An extension is to add segments to this (this is not included in this article).

The basic system has nine genes, controlling things like:

• angle of branching
• depth of branching
• number of lines
• etc. etc.

It makes use of a recursive algorithm to carry out the drawing; this is shown below:

```private void draw(Graphics g, int i, int j)
{
tree(g, i / 2, j, order, 2);
}

/// <summary>
/// Draws the Dawkins bio-morph structure (No segmentation, in this
/// implementation)
/// </summary>
/// <param name="g">The graphics to use</param>
/// <param name="i">The x position to start drawing</param>
/// <param name="j">The x position to stop drawing</param>
/// <param name="k">The y position to start drawing</param>
/// <param name="l">The y position to stop drawing</param>
private void tree(Graphics g, int i, int j, int k, int l)
{
try
{
if (l < 0)
l += 8;
if (l >= 8)
l -= 8;
int i1 = i + k * dx[l];
int j1 = j - k * dy[l];

g.DrawLine(new Pen(new SolidBrush(Color.White), 1.8F), i, j, i1, j1);
if (k > 0)
{
tree(g, i1, j1, k - 1, l - 1);
tree(g, i1, j1, k - 1, l + 1);
}
}
catch (Exception)
{
}
}```

Using this algorithm, it is possible to come up with some really interesting creatures such as:

They look very organic, don't they? However, if we introduce a segmentation (not done for this article) to the algorithm, we can then achieve some truly bizarre creatures such as these. Basically, we are using the same idea, but we are creating more segments of the same basic shape.

## Class Design

The following diagram illustrates the code design. I will give a brief discussion on each class before I show the demonstration screenshots.

Basically, there are two types of bio-morphs that I created for this article. These are:

• BioMorph, which makes use the the following classes:
• `BiomorphPanel`: Which provides the rendering for the original Dawkins Biomorph.
• `IBioEvolvalbe`: An interface which is implemented by the `BioMorphPanel` class.
• `BiomorphLayoutPanel`: Hosts a number of `BiomorphPanel` objects. This is then hosted on a Windows Form, and it is responsible for the selection of a random `BiomorphPanel`, to spawn a new generation of Dawkins Biomorphs.
• EvolvingCritter, which makes use the the following classes:
• `EvolvingCritterPanel`: Which provides the rendering for a Cow Skull type Biomorph.
• `IEvolvalbe`: An interface which is implemented by the `EvolvingCritterPanel` class.
• `CritterLayoutPanel`: Hosts a number of `EvolvingCritterPanel` objects. This is then hosted on a Windows Form, and it is responsible for the selection of the fittest `EvolvingCritterPanel`, to spawn a new generation of Dawkins Biomorphs.
• `EvolvingCritterComparator`: Provides a simple implementation of `IComparer`, to allow a collection of `EvolvingCritterPanel` objects to be sorted in order to obtain the fittest one.

There is also a common interface:

• `ILayoutPanel`: which is implemented by both `BiomorphLayoutPanel` and `CritterLayoutPanel`, which allows the Windows Form where one of these two panels is hosted to generate a new population of organisms.

## Screenshots of the Running Application

OK, so what does the application look like? Well, it depends on which of the Biomorphs is currently in use. Basically, there are two links, and depending on which one is selected, the main panel will be swapped to show the correct Biomorphs panel. It will either be a `BiomorphLayoutPanel` (Dawkins Biomorphs), or a `CritterLayoutPanel` (my own Cow Skull Biomorphs). Let's have a look at this, shall we?

### Using Dawkins BiomorphLayoutPanel BioMorphs

There is a timer placed on the form which, every 1500 milliseconds, will choose a random Dawkins Biomorph, and will use that to spawn a new population of crazy critters. There is only random selection (no tricks), and you can get some very bio-logical looking critters. Basically, it's all down to the clever gene decoding we saw earlier.

### Using CritterLayoutPanel BioMorphs (My Own Cow Skull Design)

I really only included the possibility to create other style Biomorphs for a bit of fun. The difference here is that these chaps are judged to see which one should be the one that is used for breeding. Basically, the one with the most area, and the preferred eye color, and the preferred constituent parts, will have a better score, so it will more likely be the alpha male that will be used for breeding.

Note: We do actually pick the fittest one here, so one would hope that over time, we would end up with similar shaped or colored organisms. But nature has other ideas, mutation is very powerful. Play with it a while and you will see.

### Freedom of Choice

With both these Biomorph panels, the user is also free to click on the organism they like; then this will be used as the new alpha male that is then used to create a new population.

## What Do You Think?

That's it. I would just like to ask, if you liked the article, please vote for it.

## Conclusion

I have quite enjoyed constructing this article. I hope you liked it.

## History

• v1.0: 29/01/07.

## Share

 Software Developer (Senior) United Kingdom
I currently hold the following qualifications (amongst others, I also studied Music Technology and Electronics, for my sins)

- MSc (Passed with distinctions), in Information Technology for E-Commerce
- BSc Hons (1st class) in Computer Science & Artificial Intelligence

Both of these at Sussex University UK.

Award(s)

I am lucky enough to have won a few awards for Zany Crazy code articles over the years

• Microsoft C# MVP 2015
• Codeproject MVP 2015
• Microsoft C# MVP 2014
• Codeproject MVP 2014
• Microsoft C# MVP 2013
• Codeproject MVP 2013
• Microsoft C# MVP 2012
• Codeproject MVP 2012
• Microsoft C# MVP 2011
• Codeproject MVP 2011
• Microsoft C# MVP 2010
• Codeproject MVP 2010
• Microsoft C# MVP 2009
• Codeproject MVP 2009
• Microsoft C# MVP 2008
• Codeproject MVP 2008
• And numerous codeproject awards which you can see over at my blog

## You may also be interested in...

 First Prev Next
 My vote of 5 Kenneth Haugland16-Sep-13 3:20 Kenneth Haugland 16-Sep-13 3:20
 changing code Kitten8310-Dec-11 16:31 Kitten83 10-Dec-11 16:31
 Re: changing code Sacha Barber10-Dec-11 21:38 Sacha Barber 10-Dec-11 21:38
 Leaving Java Behind logicchild9-Mar-09 22:39 logicchild 9-Mar-09 22:39
 [Message Deleted] Danny Rodriguez27-Jan-08 9:11 Danny Rodriguez 27-Jan-08 9:11
 Good Stuff! bobsugar2221-Feb-07 4:52 bobsugar222 1-Feb-07 4:52
 Re: Good Stuff! Sacha Barber1-Feb-07 7:41 Sacha Barber 1-Feb-07 7:41
 Antithesis Ilíon30-Jan-07 6:17 Ilíon 30-Jan-07 6:17
 Re: Antithesis Sacha Barber30-Jan-07 6:53 Sacha Barber 30-Jan-07 6:53
 Re: Antithesis Ilíon30-Jan-07 7:24 Ilíon 30-Jan-07 7:24
 Re: Antithesis [modified] Sacha Barber30-Jan-07 8:00 Sacha Barber 30-Jan-07 8:00
 Re: Antithesis Ilíon30-Jan-07 8:53 Ilíon 30-Jan-07 8:53
 Re: Antithesis Sacha Barber30-Jan-07 9:06 Sacha Barber 30-Jan-07 9:06
 Re: Antithesis Ilíon31-Jan-07 3:47 Ilíon 31-Jan-07 3:47
 "mmm this seems to have touched something very deep within you. Which is a little strange to me." I value clear -- rational and logically sound -- thinking. Do you not? I have always, from the time I was a child, considered it to be an obvious truth that one of the most important obligations we humans have is to *think* Related to that obligation, following from it, it seems to me is the subsidiary obligation to help one another in clarifying our mutual thought. So, yes, I suppose you may "have touched something very deep within" me. But, does this really seem strange to you? "I have just tried to show folk how to write an implementation of dawkins Biomorphs." Have I faulted you for that? Have I said your article should have no place on the Code Project? Where have I said you should be defensive about this article? Rather, I have pointed out that interesting as the results of Dawkins' 'Biomorphs' algorithm(s) may be, they have nothing at all to do with the use to which he tries to put them; I have pointed out that they have nothing at all to do -- and, in fact, are the very opposite -- of the conclusions he desires the uninformed or easily-wowed to draw from his presentation of them. It seems you have agreed: "I agree with all you comments. There is no magic, all the information is in the algorithm. Thats a given." But not to worry, were you a hard-code Dawkins-oid, I'd have let it go at what I had written to that point. Had you made it clear that you either would not or could not *think* on this matter, I'd have let it go. I would have lowered my opinion of you as an intellect, but I'd have let the matter drop. "I have just tried to show folk how to write an implementation of dawkins Biomorphs." I *seemed* to me, from reading your article, that you were endorsing Dawkins' faulty reasoning. Because I see rational and logically sound thinking as one of the primary obligations we humans have (and because I have a good opinion of you and want to continue that good opinion), it took it as my duty to get clarity on this point. "You know, It is just a demo to other folk, to you know, demystify issues ..." I have probed what I took, whether rightly or wrongly, to be your endorsement of Dawkins' faulty reasoning concerning the algorithm(s) which generate 'Biomorphs.' You have clarified on that point. Is this not a win-win situation? Have I not helped you to demystify the issue? I'm all about demystification. "Stay chilled man" For the next month of so, I have no choice but to stay chilled. Winter-like weather was late in getting to Ohio this year, but it's here now!
 Re: Antithesis Sacha Barber31-Jan-07 4:14 Sacha Barber 31-Jan-07 4:14
 Re: Antithesis un_ko31-Jan-07 2:38 un_ko 31-Jan-07 2:38
 Re: Antithesis Sacha Barber31-Jan-07 4:07 Sacha Barber 31-Jan-07 4:07
 Re: Antithesis un_ko31-Jan-07 11:57 un_ko 31-Jan-07 11:57
 Re: Antithesis Sacha Barber1-Feb-07 7:43 Sacha Barber 1-Feb-07 7:43
 Re: Antithesis Sacha Barber1-Feb-07 7:44 Sacha Barber 1-Feb-07 7:44
 Re: Antithesis [echo]6-Feb-07 20:43 [echo] 6-Feb-07 20:43
 Re: Antithesis Sacha Barber6-Feb-07 22:25 Sacha Barber 6-Feb-07 22:25
 Re: Antithesis M. Thomas Frederiksen25-Dec-07 18:11 M. Thomas Frederiksen 25-Dec-07 18:11
 Re: Antithesis Lawrence Botley8-Feb-07 2:51 Lawrence Botley 8-Feb-07 2:51
 Re: Antithesis Ilíon8-Feb-07 4:50 Ilíon 8-Feb-07 4:50
 Re: Antithesis Lawrence Botley8-Feb-07 5:19 Lawrence Botley 8-Feb-07 5:19
 Re: Antithesis Sacha Barber8-Feb-07 5:54 Sacha Barber 8-Feb-07 5:54
 Re: Antithesis [modified] Ilíon8-Feb-07 6:05 Ilíon 8-Feb-07 6:05
 Re: Antithesis Sacha Barber8-Feb-07 7:33 Sacha Barber 8-Feb-07 7:33
 Re: Antithesis Ilíon8-Feb-07 7:44 Ilíon 8-Feb-07 7:44
 Re: Antithesis Sacha Barber8-Feb-07 8:15 Sacha Barber 8-Feb-07 8:15
 Re: Antithesis easyTree4-Mar-07 3:18 easyTree 4-Mar-07 3:18
 Re: Antithesis mhunt1311-Feb-07 23:21 mhunt13 11-Feb-07 23:21
 Re: Antithesis Sacha Barber12-Feb-07 0:15 Sacha Barber 12-Feb-07 0:15
 Re: Antithesis Ilíon12-Feb-07 3:12 Ilíon 12-Feb-07 3:12
 Re: Antithesis Sacha Barber12-Feb-07 3:39 Sacha Barber 12-Feb-07 3:39
 Re: Antithesis Ilíon12-Feb-07 3:59 Ilíon 12-Feb-07 3:59
 Cool... Peter Hancock29-Jan-07 11:54 Peter Hancock 29-Jan-07 11:54
 Re: Cool... Sacha Barber29-Jan-07 21:23 Sacha Barber 29-Jan-07 21:23
 Interesting stuff WillemM29-Jan-07 9:45 WillemM 29-Jan-07 9:45
 Re: Interesting stuff Sacha Barber29-Jan-07 11:10 Sacha Barber 29-Jan-07 11:10
 Interesting Article aprenot29-Jan-07 9:03 aprenot 29-Jan-07 9:03
 Re: Interesting Article Sacha Barber29-Jan-07 9:13 Sacha Barber 29-Jan-07 9:13
 Re: Interesting Article aprenot29-Jan-07 9:31 aprenot 29-Jan-07 9:31
 Re: Interesting Article Sacha Barber29-Jan-07 11:09 Sacha Barber 29-Jan-07 11:09
 Re: Interesting Article aprenot29-Jan-07 11:50 aprenot 29-Jan-07 11:50
 Re: Interesting Article Sacha Barber29-Jan-07 21:10 Sacha Barber 29-Jan-07 21:10
 Last Visit: 31-Dec-99 18:00     Last Update: 1-Aug-15 12:19 Refresh 1