原件存檔 Original files吳哲宇 Che-Yu Wu

高三下(2013 年 5 月到 6 月)Grade 12, second term (May to June 2013)

Evolution Revolution:讓屬性跟著時間起伏的基因Evolution Revolution: genes whose traits rise and fall with time

Evolution 2012 的屬性是定值,這一版讓屬性變成時間的函數。每個生物的基因裡,有幾個固定的片段,例如 GAGGAA 出現幾次,就替速度 v 加幾個「增幅器」。每個增幅器的振幅是另一個片段(GTAAAT)出現的次數,種類是再一個片段(GATAT)出現的次數除以 9 的餘數。每個時間單位程式都把增幅器算一遍,用名字("v"、"vx"、"vy"、"copyneed"、"ang")找到生物身上對應的屬性,讀出來、套函數、寫回去。

增幅器共 9 種。第 0 種是 var + n·Sin(t),屬性繞著原值來回擺。第 1 種是 var + n·Log(Abs(Tan(t))),tan 在接近 π/2 的地方會衝向無限,取對數之後屬性偶爾發散。其他有每 100 個單位加 20、取絕對值、每 79 個單位乘 1.1,和直接歸零。

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.

這一版也有環境污染物:死掉的生物在原地留下一團紅色的污染物(命令 "copyneed,+,20"),靠近的生物的 copyneed(繁殖需要累積的量)會被改掉,量隨距離變化。有毒的生物每隔一陣子放出紫色的污染物,改變別人的 live(壽命)。滑鼠也可以放污染物。

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.