In Evolution 2012 the traits were constants; this version turns them into functions of time. In each creature's gene a few fixed fragments, for example GAGGAA, add as many "boosters" to the speed v as the fragment occurs; each booster's amplitude is the number of times another fragment (GTAAAT) occurs, and its kind is the number of times a third fragment (GATAT) occurs, modulo 9. Every time unit the program runs the boosters, finds the matching trait on the creature by name ("v", "vx", "vy", "copyneed", "ang"), reads it, applies the function and writes it back.
There are 9 kinds of booster. Kind 0 is var + n·Sin(t), the trait swinging back and forth around its value. Kind 1 is var + n·Log(Abs(Tan(t))): tan shoots towards infinity near π/2, and after the logarithm the trait now and then diverges. The others add 20 every 100 units, take the absolute value, multiply by 1.1 every 79 units, or set it to zero.
Public Function editvalue(ByVal var, ByVal t)
Dim RES As Double
editKind = editKind Mod editKindm
Select Case editKind
Case 0
RES = var + editnum * Math.Sin(t)
Case 1
RES = var + editnum * Math.Log(Math.Abs(Math.Tan(t)))
Case 2
RES = var + editnum * Math.Log(Math.Abs(Math.Sin(t)))
Case 3
If t Mod 100 = 0 Then
RES = var + 20
End If
Case 4
RES = Math.Abs(var)
Case 5
RES = var + Math.Sin(t) - Math.Cos(t + Math.PI)
Case 6
RES = var + ran.Next(0) * 2
Case 7
If t Mod 79 = 0 Then
RES = var * 1.1
End If
Case 8
RES = 0
End Select
Return RES
End Function
clsBoostA.vb:九種增幅器。clsBoostA.vb: the nine boosters.
For i As Integer = 1 To Count(DNA, "GAGGAA")
Dim clb As New clsBoost
clb.editname = "v"
clb.editnum = Count(DNA, "GTAAAT")
clb.editKind = Count(DNA, "GATAT")
BSTCOL.Add(clb)
Next
For i As Integer = 1 To Count(DNA, "TATGGA")
Dim clb As New clsBoost
clb.editname = "vx"
clb.editnum = Count(DNA, "AGGTG")
clb.editKind = Count(DNA, "TTTTA")
BSTCOL.Add(clb)
Next
…
Public Sub runboost(ByVal TTIME)
Dim clsbot As clsBoost
For Each clsbot In BSTCOL
With clsbot
Dim var As Integer = CallByName(Me, clsbot.editname, CallType.Get)
CallByName(Me, clsbot.editname, CallType.Set, clsbot.editvalue(var, TTIME))
Debug.Print(var & " " & CallByName(Me, clsbot.editname, CallType.Get))
R = R Mod 255
End With
Next
End Sub
clsCreature.vb:片段出現幾次就加幾個增幅器,和每個時間單位套用增幅器的 runboost。clsCreature.vb: as many boosters as a fragment occurs, and runboost, which applies them every time unit.
This version also has environmental pollutants: a creature that dies leaves a red pollutant where it lay (the command "copyneed,+,20"), and the copyneed of nearby creatures, the amount a creature must build up before it can reproduce, is changed by an amount that depends on the distance. A poisonous creature sends out purple pollutants at intervals that change others' live, their lifespan. The mouse can place pollutants too.