Author Topic: .sexrepro reimplemented in 2.43.1  (Read 17257 times)

Offline shvarz

  • Bot God
  • *****
  • Posts: 1341
    • View Profile
.sexrepro reimplemented in 2.43.1
« Reply #15 on: January 24, 2008, 05:28:58 PM »
Hmm, fun discussion.. I personally find both approaches interesting and can't make my mind as to which one would be better.

From a practical point of view, I just want to see something done to get sexrepro working. My worry is that it's just not going to work. The requirements that Eric plans to impose seem to require a fairly complex behavior and I think that there is no chance for sexrepro to evolve on its own.
"Never underestimate the power of stupid things in big numbers" - Serious Sam

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
.sexrepro reimplemented in 2.43.1
« Reply #16 on: January 24, 2008, 06:04:16 PM »
Quote from: shvarz
My worry is that it's just not going to work. The requirements that Eric plans to impose seem to require a fairly complex behavior and I think that there is no chance for sexrepro to evolve on its own.
I like the the shot-based fertilization method over the "look at each other" method.  So, if there are no objections, I'll change over to that for 2.43.1.

So, how likely is sexual reproduction to evolve on it's own?  Well, two things need to happen.  Bots need to evolve the placement of a value into .sexrepro and the same or a different line needs to shoot -8 shots.

I don't plan to reset .sexrepro unless sexual reproduction actually occurs (so that males can detect females in heat) so bots need only evolve the DNA to set this sysvar once in a while or have it set via altzheimers or info shots or similar.

Negative shot values are mod 8, so there is a 1 in 16 chance that an evolved shooter will be shooting fertilization shots.

So, it's doesn't stike me that it will be too difficult for sexual reproduction to evolve naturally.  Harder than asexual reproduction as it involves two bots and two sysvars, but not radically improbable I think.

Whether selection will favor it is a different question all together...
Many beers....

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
.sexrepro reimplemented in 2.43.1
« Reply #17 on: January 24, 2008, 06:21:51 PM »
Quote from: Numsgil
I respect our unspoken agreement to leave either project to the other's trust.  Even if I think your agreement in this area is more from a belief that DB3 is vaporwear.  I'll respect whatever decision you make in the end, for this simple reason that you're the one coding it, but I do not see any advantages to what you propose over what I propose, except ego stroking.  No offense intended.
None taken.

I have enough expereice to know how hard it is to build something that complex from scratch that has to be largly complete and reasonbly bug free out of the gate and get it to critical mass, particularily when your chasing a moving target (my fault).  I've long argued for the incremental approach of portting the VB version then adding the new physics, but we need not get into that again here.   So, I wouldn't go so far as to call DB3 vaporware, but it's gonna take more than some cool new physics to make it real.  No offense intended.
   
Okay, I give.   If you can articulate the psuedo code for an effecient crossover algorithm that operates on 2.43 DNA, I'll use it and put the cross operator on hold for the time being.

Quote from: Numsgil
Am I misunderstanding you here?  Isn't any value in .sexrepro implying that you're being female?  A sperm shot (or whatever you want to call it) probably would use seperate machinery than .sexrepro, right?  Maybe a -8 shot, or .jerk or something crass like that?
Correct.  Any value in .sexrepro implies your female and that your willing to devote your own expensive resources to reproduction.  I plan to use -8 shots for fertilization shots.
Many beers....

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
.sexrepro reimplemented in 2.43.1
« Reply #18 on: January 24, 2008, 07:26:07 PM »
I'll do you one better and see if I can work out an actual program demonstrating an algorithm.  Probably done in C# operating on strings, for simplicity.

I don't take offense at a vaporware-esque attitude towards DB3.  I'm keenly aware of the difficulties.  However, I think if I can get the physics working like I want (no mean feat, to be sure), the rest should be downhill.  Physics is what stopped the C++ version from being "complete".

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
.sexrepro reimplemented in 2.43.1
« Reply #19 on: January 24, 2008, 08:27:15 PM »
Here is the current crossover routine for reference:


Code: [Select]
Public Function Crossover(male As Integer, female As Integer, offspring As Integer)
Dim parent As Integer
Dim I As Integer
Dim t As Integer
Dim x As Integer

  ' The length of the offspring's DNA will be the length of the longer of the parent's DNA
  If rob(male).DnaLen > rob(female).DnaLen Then
    ReDim rob(offspring).DNA(UBound(rob(male).DNA))
  Else
    ReDim rob(offspring).DNA(UBound(rob(female).DNA))
  End If
  
  'flip a coin as to which parent goes first
  If Random(0, 1) > 0.5 Then
    parent = female
  Else
    parent = male
  End If
  
  For t = 1 To UBound(rob(offspring).DNA)
  
    ' test for hitting the end of one of the parent's DNA
    ' if we have, then if we are currently on that parent, stop.
    ' if we arn't, then copy the rest of the DNA from the other parent
    If (rob(male).DNA(t).tipo = 10) And (rob(male).DNA(t).value = 1) Or _
     (rob(female).DNA(t).tipo = 10) And (rob(female).DNA(t).value = 1) Then
      
      If (rob(parent).DNA(t).tipo = 10) And (rob(parent).DNA(t).value = 1) Then
        ' DNA copying hit the end of the parent.  The offspring's DNA length is the shorter of the two parents.
        rob(offspring).DNA(t) = rob(parent).DNA(t)
        ReDim Preserve rob(offspring).DNA(t)
      Else
        ' DNA copying is currently on the longer parent.  No end hit in copying, take the rest of the longer parent
        For x = t To UBound(rob(offspring).DNA)
          rob(offspring).DNA(x) = rob(parent).DNA(x)
        Next x
      End If
  
      Exit Function ' we're done.
    End If
    
    ' copy the base pair from the current parent
    rob(offspring).DNA(t) = rob(parent).DNA(t)
    
        
    ' If we hit a crossover point in either parent then switch parents
    If (rob(male).DNA(t).tipo = 9) And (rob(male).DNA(t).value = 5) Or _
       (rob(female).DNA(t).tipo = 9) And (rob(female).DNA(t).value = 5) Then
      'Flip a coin. 50% chance of switching parents at crossover points
      If Random(0, 1) > 0.5 Then
        If parent = female Then
          parent = male
        Else
          parent = female
        End If
        
      End If
    End If
    
  Next t

End Function
Many beers....

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
.sexrepro reimplemented in 2.43.1
« Reply #20 on: January 25, 2008, 05:45:15 PM »
Attached is an implementation of natural crossing over in C# using strings.  There are two variables which can be modified to change the sort of crossing over done: the minimum matching length (defaulted to 3 in this implementation) and the number of crossing over events (user setable at run time in this implementation).

Both of these variables could easily be set by bots to control the sort of crossing over and how it works, and thus would be subject to natural selection.  If a bot increases the minimum matching length, for instance, it means that the mate must be genetically less distant for meaningful crossing over to occur.  The more crossing over events that occur, the more evenly mixed the two genomes are (and the greater the risk of breaking parts of the DNA).  For bots, you'd probably want to express number of crossover events as a probability per matched bp instead of a hard number, so that it scales nicely with genome size.

There's an exe buried deep in this implementation.  Run it with these test cases to get a feel for the results:

A: General Washington opened the western US to colonization
B: Washington state is in the western US

A: Hi John, eat boogers and die
B: John loves to eat boogers

A: AAAAAA123456AAAAAA
B: 123BBBBBB456BB

A: ABCdefGHIJ
B: abcdefghij

Implementing this in the VB code with the DNA like it is is going to be a pain, I'll admit.  Glad I'm not the one to do it
« Last Edit: January 25, 2008, 05:47:08 PM by Numsgil »

Offline shvarz

  • Bot God
  • *****
  • Posts: 1341
    • View Profile
.sexrepro reimplemented in 2.43.1
« Reply #21 on: January 25, 2008, 06:23:13 PM »
How will this deal with highly repetitive sequences?  Some of my bots by now can be represented as:

VV1VVVV2VVVVVVVV3VV4V5v6VVVVVVV7VVVVV

where numbers are real genes and V stands for a virus.
"Never underestimate the power of stupid things in big numbers" - Serious Sam

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
.sexrepro reimplemented in 2.43.1
« Reply #22 on: January 25, 2008, 06:50:11 PM »
It matches the longest sequence possible, then recursively does the same on segments to either end of the match.  So in layman's terms it handles highly repetitive sequences very well.

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
.sexrepro reimplemented in 2.43.1
« Reply #23 on: February 04, 2008, 12:48:01 PM »
Okay, I now have this implemented using shot-based fertilization and Num's crossover algorithm.  I want to bake it for 24 hours so 2.43.1 should come out tomorrow barring unforseen issues.

Bots can now shoot -8 sperm shots.  There is no cost for this beyond the normal shot cost.  The shooter's DNA is copied to the shot (like with viruses).  .shootval operates the same way as for other shots.  

If a sperm shot impacts a bot, it fertilizes it (shell, etc. has no effect on sperm shots).   That is, the sperm DNA is copied to an internal buffer on the impacted bot.  Note that the father need no longer be alive at impact time to father offspring.  Once sperm is fired, the father is out of the loop.

Currently, bots remain fertilized for 10 cycles.  We can change this easily down the road, but it's 10 for now.  A new sysvar .fertilized (303) counts down the cycles remaining until the bot is no longer fertilized.  If the bot gets shot with another sperm shot while fertilized, that DNA replaces the previous DNA and the .fertilization counter gets set to 10 again.

If a bot sets .sexrepro to a postive value not a multiple of 100 while fertilized, it will sexually reproduce (subject to the normal reproduction constraints w.r.t. body, space and vegginess) giving the offspring the specified percentage of it's resources.

For this version, the crossover variables mentioned in Num's algorithm are internal as follows.  The minimum sequence length to match is fixed at 3 base pairs.  The maximum number of crossover points is determined by taking the length of the shorter parent's DNA and dividing by 10.

Seems to be working pretty well now.  Stay tuned...








Many beers....

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
.sexrepro reimplemented in 2.43.1
« Reply #24 on: February 04, 2008, 01:56:26 PM »
A couple of additional points:

.sexrepro only gets reset if reproduction is successful.

Reproducing sexually does not zero the fertiliziation counter.  Bots may sexually reproduce multiple times (up to 10 times, once per cycle) using the same sperm DNA.
Many beers....

Offline googlyeyesultra

  • Bot Destroyer
  • ***
  • Posts: 109
    • View Profile
.sexrepro reimplemented in 2.43.1
« Reply #25 on: February 04, 2008, 04:35:08 PM »
I just find it midly disturbing that I could insert my own DNA by info-shotting sexrepro and then firing a -8 shot.

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
.sexrepro reimplemented in 2.43.1
« Reply #26 on: February 04, 2008, 08:30:15 PM »
Quote from: googlyeyesultra
I just find it midly disturbing that I could insert my own DNA by info-shotting sexrepro and then firing a -8 shot.
Yup.  But at least buy her a drink first....  

Rape is mostly a human concept.  It's certainly a viable reproductive strategy for many males of many species.  Biologists would call it a "sneaker male strategy" or sperm competition or some such.  Something like 5% of all salmon for example are fertilized by a "sneaker male" who hides and then darts and in and sprays the eggs before the male the female selected can act.    There are insects with barbs on their penises (I kid you not) which evolution has shaped as a cone to scoop out and remove the sperm from the male before them....    Much of sexual selection and sexual apparatus adaptations are rooted in such strategies...
Many beers....

Offline rsucoop

  • Bot Destroyer
  • ***
  • Posts: 166
    • View Profile
.sexrepro reimplemented in 2.43.1
« Reply #27 on: February 04, 2008, 08:49:50 PM »
Perhaps the explosive shots could be introduced for egg use?

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
.sexrepro reimplemented in 2.43.1
« Reply #28 on: February 04, 2008, 09:15:00 PM »
Quote from: rsucoop
Perhaps the explosive shots could be introduced for egg use?
Perhaps I'll add an option for the DNA produced via crossover to replace the "mother's" DNA instead of producing a new bot, perhaps via storing a negative number to .sexrepro.   In this way, time shifted reproduction can be accomplish by a "female" bot laying an egg through asexual reproduction.  After storing a negative value to .sexrepro, the female's DNA would be coded to do bascially nothing - expending no nrg - until fertilized at which point the egg hatches with the combined DNA from both parents.

Explosive shots are a nice idea, but I don't really see them playing a role in sexual reproduction, unless of course they are filled with Tequilla....  
« Last Edit: February 04, 2008, 09:16:36 PM by EricL »
Many beers....

Offline Endy

  • Bot Overlord
  • ****
  • Posts: 852
    • View Profile
.sexrepro reimplemented in 2.43.1
« Reply #29 on: February 05, 2008, 06:16:14 AM »
Maybe the female simply becomes an egg once properly fertilized by a male. Not quite realistic, but otherwise you could knock other bots out by shooting negative values at them.

Could use explosive shots for firing multiple "sperm" or other types of shots at once. Could be handy for firing at a groups of bots or if you don't have a specific bot you want to shoot.
« Last Edit: February 05, 2008, 06:30:46 AM by Endy »