Einzelnen Beitrag anzeigen

Benutzerbild von Maya
Maya

Registriert seit: 15. Jun 2011
Ort: Potsdam-Mittelmark
107 Beiträge
 
Delphi 2010 Enterprise
 
#21

AW: Game Of Life - ich könnte etwas Hilfe gebrauchen, bitte

  Alt 15. Jun 2011, 14:41
Das dachte ich mir schon, als ich den Hinweis von DeddyH las.
Ich hab deswegen die Funktion jetzt wie folgt umgebaut.

Delphi-Quellcode:
function GameOfLife(x,y: Integer): Integer;
var Temp: Integer;
begin
  Temp:=0;
  if (x>1) and (y>1) and (Zellen[x-1,y-1]=1) then Temp:=Temp+1;
  if (y>1) and (Zellen[x,y-1]=1) then Temp:=Temp+1;
  if (x<4) and (y>1) and (Zellen[x+1,y-1]=1) then Temp:=Temp+1;

  if (x>1) and (Zellen[x-1,y]=1) then Temp:=Temp+1;
  if (x<4) and (Zellen[x+1,y]=1) then Temp:=Temp+1;

  if (x>1) and (y<4) and (Zellen[x-1,y+1]=1) then Temp:=Temp+1;
  if (y<4) and (Zellen[x,y+1]=1) then Temp:=Temp+1;
  if (x<1) and (y<4) and (Zellen[x+1,y+1]=1) then Temp:=Temp+1;

  case Temp of
  0,1,4..8: Result:=0;
  2: if (Zellen[x,y]=1) then Result:=1 else Result:=0;
  3: Result:=1;
  end;
end;
Leider stimmt das Ergebnis immer noch nicht mit dem überein, was eigentlich auftauchen sollte. Ist irgendwo ein Denkfehler noch enthalten?
Bei Optionen habe ich ausgestellt, dass die boolschen Ausdrücke vollständig überprüft werden.
  Mit Zitat antworten Zitat