Wie schnell die Zeit vergeht... hat da jemand die Simulation vorgespult?
Das war die Aufgabe
Postet hier eure Ergebnisse, Codes, Gedanken. Lernt von den anderen, seht euch deren Quelltext an und versucht euren eigenen zu verbessern.
Diskussion
Postet zu euren Codes stets eine kurze Erklärung mit euren Gedanken in denen ihr simpel gesagt die Frage "Wieso habe ich XY auf diese Art gelöst?" beantwortet. Beiträge, die nur den Code enthalten werden wir aus dem Thread entfernen.
Nächste Aufgabe
In einer Woche wird die Musterlösung nach editiert und in 2 die nächste Aufgabe eingestellt.
Viel Spaß & viel Erfolg!
Musterlösung:
BlitzMax: [AUSKLAPPEN] [EINKLAPPEN] SuperStrict SeedRnd(MilliSecs())
For Local i:Int = 1 To 5 TBunny.Create(Null) Next
Repeat Select Input("> ") Case "q", "quit", "exit" End End Select Print("") Print("New Year...") TBunny.Update() Print("Bunnys gestorben: " + TBunny.died + " (" + TBunny.Oldest + ")") Print("Bunnys geboren: " + TBunny.Born) Print("Bunnys: " + TBunny.Count) Until TBunny.Count = 0 End
Type TBunny Field name:String Field sex:Int Field age:Int Field fur:Int Global Count:Int = 0, Died:Int, Born:Int Global MaxN:Int = 200, Oldest:Int = 0 Global List:TList = New TList Function Create(mother:TBunny) Local b:TBunny = New Tbunny b.name = Randname() b.sex = Rand(0, 1) b.age = 0 If mother = Null Then b.fur = Rand(0, 2) Else b.fur = mother.fur EndIf TBunny.Count:+1 TBunny.Born:+1 TBunny.List.AddLast(b) Print(b.name + " wurde geboren! (" + FurName(b.fur) + ")") End Function Method Die() Print(Self.name + " starb im alter von " + Self.age) If Self.age > TBunny.Oldest Then TBunny.Oldest = Self.age TBunny.Died:+1 TBunny.Count:-1 TBunny.List.Remove(Self) End Method Method Ageing() Self.age:+1 If Self.age < 8 Then If (10 > Rand(0, 100)) Then Self.Die() ElseIf Self.age = 8 Then If (50 > Rand(0, 100)) Then Self.Die() ElseIf Self.age = 9 Then If (75 > Rand(0, 100)) Then Self.Die() Else If (99 > Rand(0, 100)) Then Self.Die() EndIf End Method Function Update() TBunny.Born = 0 TBunny.Died = 0 For Local b:TBunny = EachIn TBunny.List b.Ageing() Next If TBunny.Count > TBunny.MaxN Then For Local b:TBunny = EachIn TBunny.List If (75 > Rand(0, 100)) Then b.Die() Next Else For Local b:TBunny = EachIn TBunny.List If b.age >= 2 And b.sex = False Then For Local b2:TBunny = EachIn TBunny.List If b2.age >= 2 And b2.sex = True Then Print(b2.name + " bekommt ein Kind!") TBunny.Create(b2) EndIf Next Exit EndIf Next EndIf End Function End Type
Function Randname:String(_Min:Int = 3, _Max:Int = 8) Local name:String, i:Int, r:Int = Rand(_min, _max) For i = 0 Until r name:+Chr(65 + Rand(0, 24)) Next Return name End Function
Function FurName:String(nr:Int) Select nr Case 0 Return "weiss" Case 1 Return "schwarz" Case 2 Return "braun" Default Return "Rosa?!" End Select End Function
|