Author Topic: Survival-of-the-fittest evobot  (Read 16193 times)

Offline Griz

  • Bot Overlord
  • ****
  • Posts: 608
    • View Profile
Survival-of-the-fittest evobot
« Reply #30 on: February 26, 2006, 12:01:54 PM »
Quote
Quote
anyone know where in the DB code these might be found/modified?

Scripts are kind of interesting to set up.

The biggest problem I always come up against is that every robot has to parse every script in the active script list every time that they need to test the conditions against them.

This was relatively easy to set up for mutations because you only need to parse the scripts when a baby is born but for scripts in the main code, eaxh bot would have to check them all on every cycle and this could possibly cause a bit of a slowdown.

Then again maybe it ouldn't be all that bad.

Right now scripts are only parsed in the mutations module but expansions to the system will have to be called from the main code loop.
ok.

can you give me an example or two of some of the ones you
are using to pause the sim when some mutation you have
flagged is detected?
and how one would go about adding new scripts?

this seems a very powerful tool to me.

thanks
不知
~griz~
[/color]
   "The selection of Random Numbers is too important to be left to Chance"
The Mooj  a friend to all humanity
[/color]

Offline Griz

  • Bot Overlord
  • ****
  • Posts: 608
    • View Profile
Survival-of-the-fittest evobot
« Reply #31 on: February 26, 2006, 12:33:28 PM »
question:
how does this determining the Fittest used to hightlight the King Bot?
where does that happen?

Code: [Select]
For t = 1 To MaxRobs
  If rob(t).Exist And Not rob(t).Veg Then
    s = score(t, 1, 2, 0)
    If s >= Mx Then
      Mx = s
      fittest = t
    End If
  End If
Next t

'fittest' is now set to 't' ...
so now 'fittest' must be used somewhere to hightlight the bot, eh?
wouldn't rob(t).highlight = True have to also be set here ...
and not in the ScoreFunction?
what is being highlighted in ScoreFunction when tipo=1?
is that something different?

this is all very confusing. ;(
不知
~griz~
[/color]
   "The selection of Random Numbers is too important to be left to Chance"
The Mooj  a friend to all humanity
[/color]

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Survival-of-the-fittest evobot
« Reply #32 on: February 26, 2006, 01:07:18 PM »
Quote
this is all very confusing. ;(
Welcome to the club :D

If you can tinker around and get something more interesting than simply the most number of offspring, be my guest.

Offline Griz

  • Bot Overlord
  • ****
  • Posts: 608
    • View Profile
Survival-of-the-fittest evobot
« Reply #33 on: February 26, 2006, 04:12:42 PM »
it works. :D

I commented out the s=score(t,1,2,0) and just went with
s = rob(t).SonNumber and it seemed to workthe same
as before.
then used s=rob(t).SonNumber / rob(t).age ...
which I think would select a bot with a higher 'rate of reproduction'
which may be useful, who can say.  
so it looks like this will work, and you can put in whatever
criteria you want for sellecting what you might consider to be a
more fit bot.

found your Invested Energy routine and put part of it in here.
of course this only calculates that invested in the bot itself, not that
invested in it's offspring ...
and I guess that was what you were really looking for.
I will think on that a bit now that this is beginning to make some sense.
but it can at least be a factor for the bot itself.
I did scale it way down tho ...
knocking energy down by a factor of 1000 and body by 100
so I could still add in number of offspring, multiplied by 10 ...
and have all of these be factors of a similar magnitude.
the scaling of course can be altered any way one wishes.

so the line
s = rob(t).SonNumber * 10 + rob(t).nrg / 1000 + rob(t).body / 100

works pretty good, as energy can easily get up to 32000 and body
pretty high as well, not sure what the max is, I saw values of 1200 ...
so right there s = 44. but as soon as some begin reproducing ...
then # of offspring begins to come into play.
so this is what I was looking for ... a way to scale various inputs.

of course ... it should be possible to enable/disable and scale
many different inputs from an input window ...
but at this point I haven't any idea how to do so. ;)
any info to steer me towards how one might do that will be appreciated.

anyway Nums ...
looks you can put your Invested Energy into the equation here
in this limited way ... and add a nominal value for each offspring.
 
I will play with it the way you had it set up, before defaulting it to one ...
and see what I can sus out.

Code: [Select]
' returns the fittest robot (selected through the score function)  'not any more - griz
' altered from the bot with the most generations
' to the bot with the most invested energy in itself and children
Function fittest() As Integer
  Dim t As Integer
  Dim s As Double
  Dim s1 As Double
  Dim Mx As Double
  Mx = 0
  For t = 1 To MaxRobs
    If rob(t).Exist And Not rob(t).Veg Then
      's = score(t, 1, 2, 0) ' old scoring

      's = rob(t).SonNumber / rob(t).age      '# of offspring/age

      s = rob(t).SonNumber * 10 + rob(t).nrg / 1000 + rob(t).body / 100  'Num's Invested Energy plus #offspring ... all scaled

        If s >= Mx Then 'NOTE when higher = fittest
        'If s <=Mx Then 'when lower values = fittest    
        Mx = s
        fittest = t
                  'just for debugging info
                   's1 = rob(fittest).nrg  s1 = rob(fittest).body s1 = rob(fittest).SonNumber
                   's1 = rob(fittest).age s1 = rob(fittest).AbsNum
        
      End If
    End If
  Next t
End Function
不知
~griz~
[/color]
   "The selection of Random Numbers is too important to be left to Chance"
The Mooj  a friend to all humanity
[/color]

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Survival-of-the-fittest evobot
« Reply #34 on: February 26, 2006, 04:16:58 PM »
The only thing to watch out for:

The original function added the total number of descendants.  That means it searched through the bots' children's children, on and on...

Unless I'm mistaken your function would only take the immediate children into consideration.

Still, nice work.  I appreciate the effort.

Offline Griz

  • Bot Overlord
  • ****
  • Posts: 608
    • View Profile
Survival-of-the-fittest evobot
« Reply #35 on: February 26, 2006, 04:33:40 PM »
Quote
The only thing to watch out for:

The original function added the total number of descendants.  That means it searched through the bots' children's children, on and on...

Unless I'm mistaken your function would only take the immediate children into consideration.

Still, nice work.  I appreciate the effort.
yes ... I see what you were intending to bring into it.

mostly, I just want to have a way to customize how the fittest bot
is selected for whatever reason one might want to select one.

a general VB question:
once I have the program break at a certain point ...
in this case, I had it break in that fittest routine after the bot
had been selected, how would one go about finding the values
of other variables? I can see those in the routine where it break
takes place by hovering over them ...
but what if I wanted to know something else ...
for example, I could determine which bot (t) got selected ...
but wanted to then know it's absolute number so I could verify
the right one was highlighted ...
but had to resort to adding that to the routine so I could hover.
I don't have the help files for VB so ...
is there a way, perhaps another window ...
where I can type in variable names and have the value returned?

I have no idea what those watch, immediate or locals windows
are supposed to do.  well ... I couldn't make them to anything. ;)
不知
~griz~
[/color]
   "The selection of Random Numbers is too important to be left to Chance"
The Mooj  a friend to all humanity
[/color]

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Survival-of-the-fittest evobot
« Reply #36 on: February 26, 2006, 05:13:55 PM »
One of those watch/immediate etc. windows allows you to type in a variable.  It will then display the variable's contents at each point in the program flow.  I don't remember which window it is specifically.  Feel free to experiment, you can't hurt anything after all.

Offline Griz

  • Bot Overlord
  • ****
  • Posts: 608
    • View Profile
Survival-of-the-fittest evobot
« Reply #37 on: February 26, 2006, 05:32:26 PM »
Quote
One of those watch/immediate etc. windows allows you to type in a variable.  It will then display the variable's contents at each point in the program flow.  I don't remember which window it is specifically.  Feel free to experiment, you can't hurt anything after all.
at each point in the program flow?
what does that mean?
each time the variable is changed?

in the immediate window, I can type only if I break the prog.
and the only thing that does anything is if I type rob( ....
I get it telling me 0-5000 which I guess it the range of the variable.
that's it, nothing else. any variable I type in there doesn't do anything
when I continue to run the program.
surely there must be some what to do this?

I wonder why the one is called a 'watch' window?
and 'locals' I thought might be local variables.
got me.
sure would be nice to have some docs.

I don't suppose one could download only the docs portion of the
VB5 free download Endy told us about.
I was gonna get it but we're talking 400MB!!!!
不知
~griz~
[/color]
   "The selection of Random Numbers is too important to be left to Chance"
The Mooj  a friend to all humanity
[/color]

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Survival-of-the-fittest evobot
« Reply #38 on: February 26, 2006, 07:31:36 PM »
My won VB version doesn't have docs, I've had to figure out most of it myself.  THere is an online MSDN that can offer assistanc, but I don't remember exactly where that is.

Anyway, here's what I do:

Once the program breaks, go to debug->add watch.  Type in the variable you're intersted in.

A "watch" window appears.  If there's a + sign to the left of a variable, it means there's more stuff inside it.  Click that + arrow to see what's inside that variable.

Offline PurpleYouko

  • Bot God
  • *****
  • Posts: 2556
    • View Profile
Survival-of-the-fittest evobot
« Reply #39 on: February 26, 2006, 08:19:46 PM »
Quote
can you give me an example or two of some of the ones you
are using to pause the sim when some mutation you have
flagged is detected?
and how one would go about adding new scripts?

Sorry. I guess I assumed that you knew about the basic scripts that are already set up in the program.

In the "Mutations" page of the options panel, you will see a few boxes at the bottom of the window and a larger one beneath them.

Click in the leftmost of the 3 smaller boxes and a pulldown menu will appear.
As an example, select "Robot gains" from the list.

Next go to the econd box and select a specific sysvar from the pull down list there. I selected "aimsx" as I was trying to mutate a turning bot from one that travels in straight lines.

Next go to the third box and select one of the few available options. The one I used was "Pause sim and highlight bot"

Once all three boxes have values, click the button labeled "Add script" and the script will appear in the large box at the bottom of the screen.

Finally, check the box marked "DNA Scripts Enabled" and start the sim. As soon as any robot is born that has the text "aimsx" anywhere in its DNA, the program will pause and highlight the bot that has it.
If you are running with graphics disabled for greater speed, you will now need to click on the "cycle" button to update the graphical display. You will now see your bot with a yellow circle around it.

Click the normal "play" button to resume the sim.

The program can handle up to 9 of these scripts simultaineously so just keep adding them to the list.

More complex scripts that watch for specific conditions in the game will require quite a chunk of programming to make them work. There is no framework at all for them right now.
There are 10 kinds of people in the world
Those who understand binary.
and those who don't

:D PY :D

Offline Griz

  • Bot Overlord
  • ****
  • Posts: 608
    • View Profile
Survival-of-the-fittest evobot
« Reply #40 on: February 26, 2006, 09:20:05 PM »
hey ... that's pretty cool.
too bad the data only shows up with the program breaks tho ...
I was hoping to be able to watch as it runs but when running
the watch window is blanked.

isn't there a way to step thru the program from inside VB?
cycle by cycle or something along those lines?

and if not, why not? ;)

ok ... now hoping this watch window retains it's info from one session to
the next so I don't have to type them in each time but not going to hold
my breath.

by mistake I fired up version 2.4 but I see the fittest and score routines
are the same.

I reinstated your Investment Energy and it seems to work fine.

watching these values in the fittestFunction:

rob(fittest).nrg : 4624.108
rob(fittest).body * 10 : 3556.851

sure adds up to:
InvestedEnergy(fittest)  : 8180.958984375
for that bot.

and with 2 offspring:
rob(fittest).SonNumber : 2  

the score relfects more energy than just the above bot
so looks as if additional score from the offspring, eh?
score(fittest, 1, 2, 0) : 17583.1732788086

however, the numbers don't add up.
I get one of it's offspring having zero nrg and zero body ...
[the one still tied] and the other only 59 nrg and 7.5 body ...
so not sure how that translates to 17583 for the score.

and ... the bot is highlighted.
this is in version 2.4

will do the same in 2.37.6 and see what's up.

so? it looks like it sorta works to me.  ??????????
不知
~griz~
[/color]
   "The selection of Random Numbers is too important to be left to Chance"
The Mooj  a friend to all humanity
[/color]

Offline Griz

  • Bot Overlord
  • ****
  • Posts: 608
    • View Profile
Survival-of-the-fittest evobot
« Reply #41 on: February 26, 2006, 09:29:46 PM »
Quote
Sorry. I guess I assumed that you knew about the basic scripts that are already set up in the program.
I recall looking at them long ago and not having a clue what they were.
now at least I know something about them.

well great ... I had no idea one could do all that with them.
excellent.
thanks

Quote
More complex scripts that watch for specific conditions in the game will require quite a chunk of programming to make them work. There is no framework at all for them right now.
right.

my head hurts already from playing with this scoring and fittest bot thing ...
but I learned a bit about VB in the process.
who knows, by the end of the decade I may be a whizz. ;)
不知
~griz~
[/color]
   "The selection of Random Numbers is too important to be left to Chance"
The Mooj  a friend to all humanity
[/color]

Offline Griz

  • Bot Overlord
  • ****
  • Posts: 608
    • View Profile
Survival-of-the-fittest evobot
« Reply #42 on: February 26, 2006, 09:43:18 PM »
Quote
however, the numbers don't add up.
I get one of it's offspring having zero nrg and zero body ...
[the one still tied] and the other only 59 nrg and 7.5 body ...
my bad. I see why.
the robot ID's were 162 and 192, but that doesn't tell me what
robot number they are.  
unless I were to go thru all 128 bots looking for rob(t).AbsNum = 162 or 192 ...
and then using that bot number to read their body and energy ...
nah ... I think it works. ;)
不知
~griz~
[/color]
   "The selection of Random Numbers is too important to be left to Chance"
The Mooj  a friend to all humanity
[/color]

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Survival-of-the-fittest evobot
« Reply #43 on: February 26, 2006, 09:49:58 PM »
Be double sure to test it, that functions slippery.

I can help you create a pop up window to help set weights for various attributes.

Ideally I'd prefer to add it to the new C++ port, but I don't know that it's that far yet.  Maybe...

Offline Griz

  • Bot Overlord
  • ****
  • Posts: 608
    • View Profile
Survival-of-the-fittest evobot
« Reply #44 on: February 26, 2006, 10:04:43 PM »
Quote
Be double sure to test it, that functions slippery.

I can help you create a pop up window to help set weights for various attributes.

Ideally I'd prefer to add it to the new C++ port, but I don't know that it's that far yet.  Maybe...
well, I'll continue to play with it as I find time ...
this is how I learn, try something and see what happens. ;)
I first have to learn enough about something to be able to ask questions
so that's all I'm doing, playing until I run up against a block ...
and then asking about it.
so I will certainly have many questions and could use some pointers.
just give me some basics in starting a pop-up window for starters.
I figured I would go look at how your physics or costs setting get entered
into a window and maybe figure it out.

I figure the fittest calcs can use score(t,1,2,0) + a number of other variables
and weights that can be added to the score, a weight of zero effectively
taking that variable out of play.

but I have no clue as far as how to get such a window started.
so ... guess that's the place to begin. ;)

whatever we come up with in the process might then be of use to
you when you are ready to port it over. might as well work out the
bugs here, eh?  
so if you can point me in some direction, I'll do that grunt work ...
and bug you with questions and who knows, maybe be of some help.
and in the process, I discover something I didn't know before ...
which is the real reason I do anything I do. ;)

all grist for the mill.
不知
~griz~
[/color]
   "The selection of Random Numbers is too important to be left to Chance"
The Mooj  a friend to all humanity
[/color]