![]() |
Game of Life-Quellcode funzt nicht
Liste der Anhänge anzeigen (Anzahl: 1)
Hallo!
Ich habe versucht ein einfaches Game of Life nachzuprogrammieren. Im Anhang der Quellcode. Allerdings funktioniert er nicht. Könntet ihr das bitte mal überprüfen? Danke! |
Re: Quellcode funzt nicht
Kannst uns ja mal verraten wo der Fehler steckt...
So ganzen Source nützt wenig... |
Re: Quellcode funzt nicht
Der Fehler ist, dass sich die Zellen nicht richtig reproduzieren.
|
Re: Quellcode funzt nicht
Bitte gib deinem Topic einen aussagekräftigen Titel, in dem du deinen ersten Beitrag editierst.
Desweiteren würde ich dir empfehlen, den relevanten Codeabschnitt hier mal zu posten und eine genaue Fehlerberschreibung zu geben. |
Re: Game of Life-Quellcode funzt nicht
Das Problem ist, dass ich nicht weis, wo der Fehler liegt.Es gibt einfach nicht die Entwicklung wie es sollte. Der Compiler meldet aber keinen Fehler.
Den Titel habe ich abgeändert. Sorry! |
Re: Game of Life-Quellcode funzt nicht
Du musst doch eine Routine haben, wo die neuen Zellen berechnte werden oder? Und da muss ja der Fehler liegen.
|
Re: Game of Life-Quellcode funzt nicht
Ja, das weis ich auch. Ich habe 3 Stunden versucht den Fehler zu finden, aber nichts gefunden. Jetzt habe ich die Hoffnung dass mir hier jemand helfen kann. Die Methode für das Leben ist die "Life" - Prozedur im Quelltext.
|
Re: Game of Life-Quellcode funzt nicht
Ja dann poste die doch mal hier. Du kannst nicht erwarten, dass jeder dein Projeklt runterläd, kompiliert und für dich debuggt.
|
Re: Game of Life-Quellcode funzt nicht
Hier mal die Funktion:
Delphi-Quellcode:
procedure TGOL.Live;
var x,y,i: Integer; s1, s2, s3, sn: String; sl1,sl2: TStringList; begin //Reihen for y := 0 to (sl1.count)-1 do begin s2 := sl1.Strings[y]; sn := ''; if (y > 0) then s1 := sl1.Strings[y-1]; if (y < (sl1.count)-1) then s3 := sl1.strings[y+1]; //Spalten for x := 0 to Length(sl1.strings[y])-1 do begin i := 0; //-Oben- if (x > 0) and (y > 0) and (Copy(s1,x-1,1) = '1') then begin inc(i); end; if (y > 0) and (Copy(s1,x,1) = '1') then begin inc(i); end; if (x < (Length(s2))) and (y > 0) and (Copy(s1,x+1,1) = '1') then begin inc(i); end; //-Mitte- if (x > 0) and (Copy(s2,x-1,1) = '1') then begin inc(i); end; if (x < (Length(s2))) and (Copy(s2,x+1,1) = '1') then begin inc(i); end; //-Unten- if (y < ((sl1.count))) and (x > 0) and (Copy(s3,x-1,1) = '1') then begin inc(i); end; if (y < ((sl1.count))) and (Copy(s3,x,1) = '1') then begin inc(i); end; if (y < ((sl1.count))) and (x < (Length(s2))) and (Copy(s3,x+1,1) = '1') then begin inc(i); end; //-Setzen- if (i = 3) then begin sn := sn + '1'; end; if (i = 2) and (Copy(s2, x,1) = '1') then begin sn := sn + '1'; end; if (i = 2) and (Copy(s2, x,1) = '0') then begin sn := sn + '0'; end; if (i <> 3) then begin if (i <> 2) then sn := sn + '0'; end; end; sl2.Strings[y] := sn; end; sl1 := sl2; View(sl1); end; |
Re: Game of Life-Quellcode funzt nicht
Mache es jetzt mit folgendem Code. Er funzt.
Delphi-Quellcode:
procedure TGOL.Live;
var x,y,i,n, n2, w: Integer; s1, s2, s3, sn, strings: String; begin {sl2 rücksetzen for n := 0 to (sl2.Count)-1 do begin sl2.Strings[n] := '000000000000'; end; } //Reihen strings := ''; for y := 0 to trunc(self.Height / zoom) do begin try s2 := sl1.Strings[y+1]; except end; sn := ''; try s1 := sl1.Strings[y]; except end; try s3 := sl1.strings[y+2]; except end; //Spalten try for x := 0 to Length(sl1.strings[y])-1 do begin i := 0; //-Oben- try if (Copy(s1,x,1) = '1') then inc(i); except end; try if (Copy(s1,x+1,1) = '1') then inc(i); except end; try if (Copy(s1,x+2,1) = '1') then inc(i); except end; //-Mitte- try if (Copy(s2,x,1) = '1') then inc(i); except end; try if Copy(s2,x+2,1) = '1' then inc(i); except end; //-Unten- try if (Copy(s3,x,1) = '1') then inc(i); except end; try if (Copy(s3,x+1,1) = '1') then inc(i); except end; try if Copy(s3,x+2,1) = '1' then inc(i); except end; //-Setzen- if (i = 3) then sn := sn + '1'; if (i = 2) and (Copy(s2, x+1,1) = '1') then sn := sn + '1'; if (i = 2) and (Copy(s2, x+1,1) = '0') then sn := sn + '0'; if (i <> 2) then if (i <> 3) then sn := sn + '0'; sl2.Strings[y] := sn; end; except end; end; inc (z); for w := 0 to round(self.width / zoom) do begin Insert('0', strings, 0); end; sl1.Insert (0,strings); sl1 := sl2; for n2 := 0 to sl1.Count-1 do begin for n := 0 to Length(sl1.strings[n2])+z do begin if Copy(sl1.strings[n2],n,1) = '1' then Canvas.Brush.Color := clYellow else Canvas.Brush.Color := clGray; Canvas.Rectangle(n*zoom, (n2+1)*zoom, n*zoom+zoom, (n2+1)*zoom+zoom); end; end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:06 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz