Click here to Skip to main content
6,306,412 members and growing! (17,731 online)
Email Password   helpLost your password?
Languages » C# » General     Intermediate

AI : Dawkins Biomorphs / And other evolving creatures

By Sacha Barber

An implementation of Dawkins biomorphs and some more crazy evolving creatures
C#, Windows, .NET, Visual Studio, Dev
Posted:29 Jan 2007
Views:38,550
Bookmarked:37 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
30 votes for this article.
Popularity: 6.53 Rating: 4.42 out of 5
2 votes, 6.7%
1

2
1 vote, 3.3%
3
4 votes, 13.3%
4
23 votes, 76.7%
5

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 results 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. Thats 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).

Basic system has 9 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 dont 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. ill give a brief discussion on each class before I show the demonstration screen shots.

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

  • BioMorph, which makes use the the following classes :
    • BiomorphPanel : Which provides the rendering for the orginal 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 reponsible 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 reponsible for the selection of the fitest EvolvingCritterPanel, to spawn a new generation of Dawkins Biomorphs
    • EvolvingCritterComparator : Provides a simple implementaion of IComparer, to allow a collection of EvolvingCritterPanel object to be sorted, in order to obtain the fitest one

There is also a common interface :

ILayoutPanel : Is a common interface which is implemented by both BiomorphLayoutPanel and CritterLayoutPanel, which allows the Windows.form where one of these 2 panels is hosted to generate a new population of organisms.

Screen Shots 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 2 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). Lets have a look at this shall we.

Using Dawkins BiomorphLayoutPanel BioMorphs

There is a timer placed on the form which every 1500 milli seconds 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 its 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 most area, and the prefferred eye color, and prefferred constiuent parts will have a better score, so will be more likely to be the aplha male, that will be used for breeding.

NOTE : We do actually pick the fitest one here, so one would hope that over time we would end up with simliar 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 ?

Thats 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 lot 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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Sacha Barber


Member
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)

Occupation: Software Developer (Senior)
Location: United Kingdom United Kingdom

Other popular C# articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 44 (Total in Forum: 44) (Refresh)FirstPrevNext
GeneralLeaving Java Behind Pinmemberlogicchild23:39 9 Mar '09  
General[Message Deleted] PinmemberDanny Rodriguez10:11 27 Jan '08  
GeneralGood Stuff! Pinmemberbobsugar2225:52 1 Feb '07  
GeneralRe: Good Stuff! PinmemberSacha Barber8:41 1 Feb '07  
GeneralAntithesis PinmemberIlíon7:17 30 Jan '07  
GeneralRe: Antithesis PinmemberSacha Barber7:53 30 Jan '07  
GeneralRe: Antithesis PinmemberIlíon8:24 30 Jan '07  
GeneralRe: Antithesis [modified] PinmemberSacha Barber9:00 30 Jan '07  
GeneralRe: Antithesis PinmemberIlíon9:53 30 Jan '07  
GeneralRe: Antithesis PinmemberSacha Barber10:06 30 Jan '07  
GeneralRe: Antithesis PinmemberIlíon4:47 31 Jan '07  
GeneralRe: Antithesis PinmemberSacha Barber5:14 31 Jan '07  
GeneralRe: Antithesis Pinmemberun_ko3:38 31 Jan '07  
GeneralRe: Antithesis PinmemberSacha Barber5:07 31 Jan '07  
GeneralRe: Antithesis Pinmemberun_ko12:57 31 Jan '07  
GeneralRe: Antithesis PinmemberSacha Barber8:43 1 Feb '07  
GeneralRe: Antithesis PinmemberSacha Barber8:44 1 Feb '07  
GeneralRe: Antithesis Pinmember[echo]21:43 6 Feb '07  
GeneralRe: Antithesis PinmemberSacha Barber23:25 6 Feb '07  
GeneralRe: Antithesis PinsussM. Thomas Frederiksen19:11 25 Dec '07  
GeneralRe: Antithesis PinmemberLawrence Botley3:51 8 Feb '07  
GeneralRe: Antithesis PinmemberIlíon5:50 8 Feb '07  
GeneralRe: Antithesis PinmemberLawrence Botley6:19 8 Feb '07  
GeneralRe: Antithesis PinmemberSacha Barber6:54 8 Feb '07  
GeneralRe: Antithesis [modified] PinmemberIlíon7:05 8 Feb '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 29 Jan 2007
Editor:
Copyright 2007 by Sacha Barber
Everything else Copyright © CodeProject, 1999-2009
Web13 | Advertise on the Code Project