Difference between revisions of "King Bot"

From WikiManual
Jump to: navigation, search
 
m
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
Selects the most successful bot for a given value of success. Typically this is the bot with the most offspring.
 
Selects the most successful bot for a given value of success. Typically this is the bot with the most offspring.
 +
----
 +
 +
The below code demonstrates how the code determines which bot is the "fittest"
 +
 +
 +
''would someone please explain how it does so?<br>
 +
''exactly where in this code is the number of offspring entered?<br>
 +
''what does s(t,1,2,0) mean?
 +
''how might one use other factors, weighted or whatever, to contribute<br>
 +
''to the score?<br>
 +
how about a breakdown of the code or some hints using the [[Talk:King_Bot|discussion]] tab above?
 +
 +
'''Update''' found out how to alter them a bit. see discussions. {{User:Griz/sig}}
 +
 +
<pre>
 +
' returns the fittest robot (selected through the score function)
 +
' 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 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)
 +
      If s >= Mx Then
 +
        Mx = s
 +
        fittest = t
 +
      End If
 +
    End If
 +
  Next t
 +
End Function
 +
</pre>
 +
 +
<pre>
 +
' does various things: with
 +
' tipo=0 returns the number of descendants for maxrec generations
 +
' tipo=1 highlights the descendants
 +
' tipo=2 searches up the tree for eldest ancestor, then down again
 +
' tipo=3 draws the lines showing kinship relations
 +
Function score(ByVal r As Integer, ByVal reclev As Integer, maxrec As Integer,
 +
 +
tipo As Integer) As Double
 +
  Dim al As Integer
 +
  Dim dx As Single
 +
  Dim dy As Single
 +
  Dim cr As Long
 +
  Dim ct As Long
 +
  Dim t As Integer
 +
  If tipo = 2 Then plines (r)
 +
  score = 0
 +
  For t = 1 To MaxRobs
 +
    If rob(t).Exist Then
 +
      If rob(t).parent = rob(r).AbsNum Then
 +
        If reclev < maxrec Then score = score + score(t, reclev + 1, maxrec, tipo)
 +
        score = score + InvestedEnergy(t)
 +
        If tipo = 1 Then rob(t).highlight = True
 +
        If tipo = 3 Then
 +
          dx = (rob(r).pos.x - rob(t).pos.x) / 2
 +
          dy = (rob(r).pos.y - rob(t).pos.y) / 2
 +
          cr = RGB(128, 128, 128)
 +
          ct = vbWhite
 +
          If rob(r).AbsNum > rob(t).AbsNum Then
 +
            cr = vbWhite
 +
            ct = RGB(128, 128, 128)
 +
          End If
 +
          Line (rob(t).pos.x, rob(t).pos.y)-Step(dx, dy), ct
 +
          Line -(rob(r).pos.x, rob(r).pos.y), cr
 +
        End If
 +
      End If
 +
    End If
 +
  Next t
 +
  If tipo = 1 Then
 +
    Form1.Cls
 +
    DrawAllRobs
 +
  End If
 +
End Function
 +
</pre>
 +
[[Category:Bottype]]

Latest revision as of 16:43, 26 February 2006

Selects the most successful bot for a given value of success. Typically this is the bot with the most offspring.


The below code demonstrates how the code determines which bot is the "fittest"


would someone please explain how it does so?
exactly where in this code is the number of offspring entered?
what does s(t,1,2,0) mean? how might one use other factors, weighted or whatever, to contribute
to the score?
how about a breakdown of the code or some hints using the discussion tab above?

Update found out how to alter them a bit. see discussions. Griztalk

' returns the fittest robot (selected through the score function)
' 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 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)
      If s >= Mx Then
        Mx = s
        fittest = t
      End If
    End If
  Next t
End Function
' does various things: with
' tipo=0 returns the number of descendants for maxrec generations
' tipo=1 highlights the descendants
' tipo=2 searches up the tree for eldest ancestor, then down again
' tipo=3 draws the lines showing kinship relations
Function score(ByVal r As Integer, ByVal reclev As Integer, maxrec As Integer, 

tipo As Integer) As Double
  Dim al As Integer
  Dim dx As Single
  Dim dy As Single
  Dim cr As Long
  Dim ct As Long
  Dim t As Integer
  If tipo = 2 Then plines (r)
  score = 0
  For t = 1 To MaxRobs
    If rob(t).Exist Then
      If rob(t).parent = rob(r).AbsNum Then
        If reclev < maxrec Then score = score + score(t, reclev + 1, maxrec, tipo)
        score = score + InvestedEnergy(t)
        If tipo = 1 Then rob(t).highlight = True
        If tipo = 3 Then
          dx = (rob(r).pos.x - rob(t).pos.x) / 2
          dy = (rob(r).pos.y - rob(t).pos.y) / 2
          cr = RGB(128, 128, 128)
          ct = vbWhite
          If rob(r).AbsNum > rob(t).AbsNum Then
            cr = vbWhite
            ct = RGB(128, 128, 128)
          End If
          Line (rob(t).pos.x, rob(t).pos.y)-Step(dx, dy), ct
          Line -(rob(r).pos.x, rob(r).pos.y), cr
        End If
      End If
    End If
  Next t
  If tipo = 1 Then
    Form1.Cls
    DrawAllRobs
  End If
End Function