Click here to Skip to main content
15,892,965 members
Articles / Programming Languages / C#

AI: Dawkins Biomorphs / And Other Evolving Creatures

Rate me:
Please Sign up or sign in to vote.
4.80/5 (35 votes)
29 Jan 2007CPOL4 min read 167.9K   964   56   48
An implementation of Dawkins Biomorphs and some more crazy evolving creatures.

Image 1

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:

C#
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:

Image 2

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.

Image 3

Class Design

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

Image 4

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.

Image 5

Image 6

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.

Image 7

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.

Sources

  1. http://www.informatics.sussex.ac.uk/users/rudil/FAI_WEB_PAGES/DawkinsBiomorphs.htm

History

  • v1.0: 29/01/07.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United Kingdom 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 2016
  • Codeproject MVP 2016
  • 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

Comments and Discussions

 
GeneralRe: Antithesis Pin
Ilíon8-Feb-07 4:50
Ilíon8-Feb-07 4:50 
"I find it quite strange that you would put forward such a strong and aggressive argument"

No doubt you have a good point -- but, of course, for the sake of consistency, it is doubtless not a "strong and aggressive" point. I *should* have presented a weak and passive argument; or at worst, a weak and passive-aggressive argument. So sorry! I'll try better in the future and I do not doubt that I can get many invaluable pointers in this regard by attending to your argument(s) Cool | :cool:


"Just because you live in England doesn't mean you have to pay any special attention to that self-deceiving man."
What a strange link to make? Unsure | :~
You're right, you're right! I *should* have said, "Just because you live on the planet Earth doesn't mean you have to pay any special attention to that self-deceiving man." Clarity and precision is so refreshing, don't you agree?

"If you feel so strongly why don't you use your intellect and constructively put together an article instead of making remarks like an angry teenager."

Dewd! Chill, dewd!

It has nothing to do with "feeling strongly." It has to do seeking clarification on Sasha's seeming endorsement of Dawkins' intentional misrepresentations of what algorithms are and what they are capable of doing.

Sasha has indicated that he agrees with the points I made in seeking that clarification (and he has indicated that he doesn't want to discuss the matter further).

Perhaps this is really none of your business at this point.

It was in *this* article that the author of this article seemed to be endorsing Dawkins' intentional misrepresentations of what algorithms are and what they are capable of doing. My writing of a seperate article would have done nothing to clarify the seeming unclarity in *this* article.

Why, one might almost think himself justified in speculating that that is the point or objective of this objection to my "strong and aggressive" argument.

"Sacha is a well respected and well read member of the codeproject community so perhaps you shouldn't be so flippant in rubbishing his concepts."

What does the respect afforded Sasha have to do with the price of scones at Oxford? Is this some sort of weak and passive "argument from authority" combined with an "appeal to popularity?"

Did I really rubbish Sasha's concepts? And if I did, why is it objectionable that I did so "flippantly?" On what grounds is this alleged flippancy to be condemned? And -- this is important, perhaps even "strong," if you will please pardon that -- if I *did* rubbish his concepts with flippancy, then they must not have been very strong concepts in the first place.

But, perhaps I misunderstand this usage of "rubbish." I take it to mean "make rubbish of" or "show the lack-of-worth of" or "show the weakness of."

Now, if Sasha's concepts were weak, did I not do him a great favor in helping him to be aware of that? For, if no one were to make him aware that his concepts were weak (we are assuming for the moment that they were), and as one presumes he'd not intentionally put forward concepts that he already knew to be weak, how, exactly, was he to become aware of this fact? Was he supposed to stumble across it accidentally? Were his concepts supposed to tell them that they were weak? Was it perhaps that Mr Dawkins was supposed to give him a ring and clue him in?

If Sasha's concepts were so weak that mere (alleged) flippancy can rubbish them, is it not the obligation of someone who can see that weakness to bring it to his attention so that he can decide whether to re-think and remove the weakness(es)?

Or, is that too "strong and aggressive?"
GeneralRe: Antithesis Pin
Lawrence Botley8-Feb-07 5:19
Lawrence Botley8-Feb-07 5:19 
GeneralRe: Antithesis Pin
Sacha Barber8-Feb-07 5:54
Sacha Barber8-Feb-07 5:54 
GeneralRe: Antithesis [modified] Pin
Ilíon8-Feb-07 6:05
Ilíon8-Feb-07 6:05 
GeneralRe: Antithesis Pin
Sacha Barber8-Feb-07 7:33
Sacha Barber8-Feb-07 7:33 
GeneralRe: Antithesis Pin
Ilíon8-Feb-07 7:44
Ilíon8-Feb-07 7:44 
GeneralRe: Antithesis Pin
Sacha Barber8-Feb-07 8:15
Sacha Barber8-Feb-07 8:15 
GeneralRe: Antithesis Pin
easyTree4-Mar-07 3:18
easyTree4-Mar-07 3:18 
GeneralRe: Antithesis Pin
mrwh11-Feb-07 23:21
mrwh11-Feb-07 23:21 
GeneralRe: Antithesis Pin
Sacha Barber12-Feb-07 0:15
Sacha Barber12-Feb-07 0:15 
GeneralRe: Antithesis Pin
Ilíon12-Feb-07 3:12
Ilíon12-Feb-07 3:12 
GeneralRe: Antithesis Pin
Sacha Barber12-Feb-07 3:39
Sacha Barber12-Feb-07 3:39 
GeneralRe: Antithesis Pin
Ilíon12-Feb-07 3:59
Ilíon12-Feb-07 3:59 
GeneralCool... Pin
Peter Hancock29-Jan-07 11:54
Peter Hancock29-Jan-07 11:54 
GeneralRe: Cool... Pin
Sacha Barber29-Jan-07 21:23
Sacha Barber29-Jan-07 21:23 
GeneralInteresting stuff Pin
WillemM29-Jan-07 9:45
WillemM29-Jan-07 9:45 
GeneralRe: Interesting stuff Pin
Sacha Barber29-Jan-07 11:10
Sacha Barber29-Jan-07 11:10 
GeneralInteresting Article Pin
aprenot29-Jan-07 9:03
aprenot29-Jan-07 9:03 
GeneralRe: Interesting Article Pin
Sacha Barber29-Jan-07 9:13
Sacha Barber29-Jan-07 9:13 
GeneralRe: Interesting Article Pin
aprenot29-Jan-07 9:31
aprenot29-Jan-07 9:31 
GeneralRe: Interesting Article Pin
Sacha Barber29-Jan-07 11:09
Sacha Barber29-Jan-07 11:09 
GeneralRe: Interesting Article Pin
aprenot29-Jan-07 11:50
aprenot29-Jan-07 11:50 
GeneralRe: Interesting Article Pin
Sacha Barber29-Jan-07 21:10
Sacha Barber29-Jan-07 21:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.