Einzelnen Beitrag anzeigen

Benutzerbild von R2D2
R2D2

Registriert seit: 20. Jan 2006
Ort: München
253 Beiträge
 
Delphi 2005 Personal
 
#9

Re: Game of Life-Quellcode funzt nicht

  Alt 20. Feb 2006, 14:21
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;
  Mit Zitat antworten Zitat