Two points. Yes it can be done in perl, it can be done in any programming language. I've done it in QBasic and in VisualBasic (screen saver fun).

Second point, "Like in real-world evolution, the mutations couldn't be completely random, and hopefully would help the creatures to survive -- but other creatures will also be evolving." errr what? Real-world mutations *are* random and arn't driven towards helping creatures survive. Sometimes mutations help and sometimes they give an individual enough of a benefit that they will have higher survival rates and so that mutation will survive. Realy the point is you want your mutations random because you don't know what will make things survive better. In the paste when playing with this problem I found that picking a set of attributes (like 20 or so) and storing them in a string (the dna if you will), then randomly mutating and crossing genes from two individuals can work. You have to be pretty carefull about how you store and retrieve the data or eventualy you get a mess.

One other thing I experimented with was having characters in the gene that mean different things. I.e. some of them related to the drawing of the creature and some the color, others the speed, turn rate etc. Then to figure out what attributes the creature has your read there dna. I'm not sure thats clear so here is an example. Lets say that a = speed++, b = speed--, c = turn rate ++, d = turn rate --. Then we take a creature whos DNA is "aaabbabcd", they have a speed of (4 - 2) and a turn rate of (0). In this way you can mutate the dna but you are always gauranteed to get the data you need, some creatures like this one will die pretty fast because they can't turn, etc. This could be expanded with more complex multi letter genes in the DNA but you get the idea. Just a few ideas, good luck and share what you come up with!


___________
Eric Hodges

In reply to Re: Using Perl to simulate evolution. by eric256
in thread Using Perl to simulate evolution. by Mychael

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.