Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Module Module1
- Dim forms() As life
- Dim RandomFeed As Int32 = 3
- Public Structure cordinate
- Dim x As Int16
- Dim y As Int16
- End Structure
- Public Structure life
- Dim energy As Int64
- Dim cord As cordinate
- Dim startenergy As Int16
- Dim breadsize As Int16
- Dim genetics As String
- End Structure
- Sub Main()
- For i = 0 To Second(Now) + 5
- Random(10)
- Next
- ReDim forms(0)
- CreateAnimal(forms(0), ToLife(Random(100), Random(100), 0, 10000, 2000, "A")) 'animal , startsize = 01000, beedsize = 020000
- Console.WriteLine(forms(0).energy)
- Console.WriteLine(forms(0).cord.x & "," & forms(0).cord.y)
- Console.ReadLine()
- Do
- ReDim Preserve forms(forms.GetLength(0) + 2)
- CreatePlant(forms(forms.GetLength(0) - 3))
- CreatePlant(forms(forms.GetLength(0) - 2))
- CreatePlant(forms(forms.GetLength(0) - 1))
- For i = 1 To 100
- MoveAnimals(forms)
- check()
- Next
- Console.WriteLine("Number of creatures: " & forms.GetLength(0))
- Console.WriteLine("Energy: " & forms(0).energy)
- Console.WriteLine("Mother energy: " & (forms(forms.GetLength(0) - 1).breadsize) - (forms(forms.GetLength(0) - 1).startenergy))
- Console.ReadLine()
- Loop
- Console.Read()
- End Sub
- Public Function Random(ByVal maxnum As Integer)
- RandomFeed = RandomFeed ^ 2 Mod (97 * 99989)
- Random = Int(1 + (RandomFeed / 10000000.0) * maxnum)
- End Function
- Sub CreatePlant(ByRef plant As life)
- plant.cord.x = Random(100)
- plant.cord.y = Random(100)
- plant.energy = 1000
- plant.genetics = "P05000" 'plant, energycontent 05000
- End Sub
- Function ToLife(ByVal x As Int16, ByVal y As Int16, ByVal energy As Int64, ByVal startsize As Int16, ByVal breadsize As Int16, ByVal genetics As String) As life
- ToLife.cord.x = x
- ToLife.cord.y = y
- ToLife.energy = energy
- ToLife.startenergy = startsize
- ToLife.breadsize = breadsize
- ToLife.genetics = genetics
- End Function
- Sub CreateAnimal(ByRef animal As life, ByVal parent As life)
- animal.cord = parent.cord
- animal.energy = parent.startenergy
- animal.genetics = parent.genetics
- animal.startenergy = parent.startenergy + Random(100) - 50
- animal.breadsize = parent.breadsize + Random(100) - 50
- If animal.breadsize <= animal.startenergy Then
- animal.breadsize = animal.startenergy
- End If
- End Sub
- Public Function MapAdd(ByVal Number1, ByVal number2)
- MapAdd = Number1 + number2
- If MapAdd - 100 > 0 Then
- MapAdd = MapAdd - 100
- ElseIf MapAdd + 100 < 100 Then
- MapAdd = MapAdd + 100
- End If
- End Function
- Sub MoveAnimals(ByRef lifelist() As life)
- Dim list2() As life
- Dim i As Int16 = 0
- Dim thismax As Integer = lifelist.GetLength(0) - 1
- Do
- If i > thismax Then
- Exit Do
- End If
- If lifelist(i).genetics = "A" Then
- If lifelist(i).energy > 0 Then
- 'move the animal
- MoveAnimal(lifelist(i))
- End If
- End If
- If forms(i).energy <= 0 Then
- Console.WriteLine("A death: " & i)
- Console.WriteLine("Type: " & lifelist(i).genetics)
- 'the animal is dead
- 'get a second array ready
- ReDim list2(lifelist.GetLength(0) - 2)
- 'move the entries before
- For n = 0 To i - 1
- list2(n) = lifelist(n)
- Next
- 'move the entires after
- For n = i + 1 To lifelist.GetLength(0) - 1
- list2(n - 1) = lifelist(n)
- Next
- 'make the first array smaller
- ReDim lifelist(list2.GetLength(0) - 1)
- 'transphure the entries back across
- lifelist = list2
- thismax = thismax - 1
- End If
- i = i + 1
- Loop
- End Sub
- Sub MoveAnimal(ByRef animal As life)
- 'defining the cariables that hold the movement direction
- 'and settig them to a random number from -1 to 1
- Dim xMove As Int16 = Random(3) - 2
- Dim yMove As Int16 = Random(3) - 2
- animal.cord.x = MapAdd(animal.cord.x, xMove)
- animal.cord.y = MapAdd(animal.cord.y, yMove)
- animal.energy = animal.energy - 1
- If animal.energy < 0 Then
- 'die
- End If
- End Sub
- Sub EatPlant(ByRef Animal As life, ByRef Plant As life)
- Animal.energy = Animal.energy + Plant.energy
- Plant.energy = 0
- Plant.cord.x = Random(100)
- Plant.cord.y = Random(100)
- End Sub
- Sub check()
- For n = 0 To forms.GetLength(0) - 1
- 'if this is an animal
- If Mid(forms(n).genetics, 1, 1) = "A" Then
- 'check for food--------------------------------------------------------------------------------------
- For i = 0 To forms.GetLength(0) - 1
- If i <> n Then
- 'if the animal is close to the plant in the x
- If forms(n).cord.x < forms(i).cord.x + 10 And forms(n).cord.x > forms(i).cord.x - 10 Then
- 'if the animal close to the plant in the y
- If forms(n).cord.y < forms(i).cord.y + 10 And forms(n).cord.y > forms(i).cord.y - 10 Then
- 'eat the plant
- EatPlant(forms(n), forms(i))
- Console.WriteLine("Animal:" & n & "," & forms(n).energy)
- End If
- End If
- End If
- Next
- 'check weather it can bread------------------------------------------------------------------------------------------
- If forms(n).energy > forms(n).breadsize Then
- ReDim Preserve forms(forms.GetLength(0))
- CreateAnimal(forms(forms.GetLength(0) - 1), forms(n))
- forms(n).energy = forms(n).energy - forms(n).startenergy
- Console.WriteLine("A Birth: " & forms(forms.GetLength(0) - 1).breadsize)
- End If
- End If
- Next
- End Sub
- End Module
Advertisement
Add Comment
Please, Sign In to add comment