Autor |
Beitrag |
Narses
      

Beiträge: 10183
Erhaltene Danke: 1256
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: So 15.03.15 15:46
Moin!
Und, klappt´s jetzt (ich sag mal: nein  )?
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Nini 
      
Beiträge: 170
Erhaltene Danke: 12
|
Verfasst: So 15.03.15 15:55
hast recht, es geht nicht
es verändert sich eine generation lang und dann bleibt's stehn
|
|
Narses
      

Beiträge: 10183
Erhaltene Danke: 1256
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: So 15.03.15 15:56
Moin!
Jo, so ist es.  Also: kannst den Button-Aufruf da wieder raus nehmen.
Wie funktioniert denn ein Timer? Haben wir irgendwo gesagt, was der machen soll?
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Nini 
      
Beiträge: 170
Erhaltene Danke: 12
|
Verfasst: So 15.03.15 15:59
nein, also so wirklich hab ich keine ahnung wie timer funktionieren :/
|
|
Narses
      

Beiträge: 10183
Erhaltene Danke: 1256
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: So 15.03.15 16:00
Moin!
Dann mach doch mal einen Doppelklick auf der Timer-Komponenten im Formular...
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Nini 
      
Beiträge: 170
Erhaltene Danke: 12
|
Verfasst: So 15.03.15 16:01
damit hab ich eine weitere prozedur geöffnet.
muss ich da jetzt reinschreiben, dass er den rechnenbutton ausführen soll?
|
|
Narses
      

Beiträge: 10183
Erhaltene Danke: 1256
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: So 15.03.15 16:07
Moin!
Nini hat folgendes geschrieben : | muss ich da jetzt reinschreiben, dass er den rechnenbutton ausführen soll? |
Jup.
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
Für diesen Beitrag haben gedankt: Nini
|
|
Nini 
      
Beiträge: 170
Erhaltene Danke: 12
|
Verfasst: So 15.03.15 16:09
|
|
Narses
      

Beiträge: 10183
Erhaltene Danke: 1256
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: So 15.03.15 16:35
Moin!
Wie sieht´s aus, rein von der Aufgabe her bist du fertig: Game of Life läuft.
Willst du noch ein bisschen optimieren?  Evtl. könnte man ja die Feldgröße unabhängig von manuell angelegten Shapes machen? (man kann die Shapes auch per Programmcode anlegen und muss dann nur noch N ändern, wenn man das Feld größer machen möchte  )
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Nini 
      
Beiträge: 170
Erhaltene Danke: 12
|
Verfasst: So 15.03.15 16:47
joar, das hört sich gut an
kann man eigentlich das programm auch so ändern, dass der nutzer die regeln für geburt/tod ändern können?
|
|
Narses
      

Beiträge: 10183
Erhaltene Danke: 1256
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: So 15.03.15 17:06
Moin!
Nini hat folgendes geschrieben : | joar, das hört sich gut an  |
Gut, dann schauen wir mal, was noch geht.
Nini hat folgendes geschrieben : | kann man eigentlich das programm auch so ändern, dass der nutzer die regeln für geburt/tod ändern können? |
Mann kann schon, die Frage ist eher: kann Frau auch?  (soll heißen: ja, klar kann man, aber wenn du keine Idee hast wie, könnte es noch etwas schwer sein für dich, oder?)
Dann zeig doch bitte erstmal deinen kompletten Code, damit ich den aktuellen Status kenne.
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Nini 
      
Beiträge: 170
Erhaltene Danke: 12
|
Verfasst: So 15.03.15 17:21
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172:
| unit Unit1;
{$mode objfpc}{$H+}
interface
uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;
const N = 5; type TFeld = array[0..N-1, 0..N-1] of Boolean;
TForm1 = class(TForm) ckAutomatik: TCheckBox; Ende: TButton; Shape1: TShape; Shape10: TShape; Shape11: TShape; Shape12: TShape; Shape13: TShape; Shape14: TShape; Shape15: TShape; Shape16: TShape; Shape17: TShape; Shape18: TShape; Shape19: TShape; Shape2: TShape; Shape20: TShape; Shape21: TShape; Shape22: TShape; Shape23: TShape; Shape24: TShape; Shape25: TShape;
Timer: TTimer; procedure btnLesenClick(Sender: TObject); procedure btnRechnenClick(Sender: TObject); procedure btnSchreibenClick(Sender: TObject); procedure ckAutomatikChange(Sender: TObject); procedure EndeClick(Sender: TObject); procedure Shape1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure TimerTimer(Sender: TObject);
private
public Feld: TFeld; function LebtNachbar(x, y: Integer): Boolean; function AnzahlLebenderNachbarn(const x, y: Integer): Integer; end;
var Form1: TForm1;
implementation
{$R *.lfm}
function TForm1.LebtNachbar(x, y: Integer): Boolean; begin if (x < 0) then x := x +N; if (y < 0) then y := y +N; if (x > (N-1)) then x := x -N; if (y > (N-1)) then y := y -N; Result := Feld[x, y]; end;
function TForm1.AnzahlLebenderNachbarn(const x, y: Integer): Integer; var dx, dy: Integer; begin Result := 0; for dy := -1 to 1 do for dx := -1 to 1 do begin if not ((dx=0) and (dy=0)) then if LebtNachbar(x +dx, y +dy) then Inc(Result); end; end;
procedure TForm1.btnSchreibenClick(Sender: TObject); var x, y, snr: Integer; Shape: TShape; begin for y := 0 to N-1 do for x := 0 to N-1 do begin snr := x +y *N +1; Shape := TShape(FindComponent('Shape' +IntToStr(snr))); if (feld[x,y]) then shape.brush.color := clblack else shape.brush.color := clwhite; end;
end;
procedure TForm1.ckAutomatikChange(Sender: TObject); begin if ckAutomatik.Checked then begin btnLesenClick(Self); Timer.Enabled := True; end else Timer.Enabled := False; end;
procedure TForm1.EndeClick(Sender: TObject); begin close; end;
procedure TForm1.Shape1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var ThisShape: TShape; begin ThisShape := (Sender as TShape); if (ThisShape.Brush.Color = clWhite) then ThisShape.Brush.Color := clBlack else ThisShape.Brush.Color := clWhite; end;
procedure TForm1.TimerTimer(Sender: TObject); begin btnrechnenClick(Self); end;
procedure TForm1.btnLesenClick(Sender: TObject); var x, y, snr: Integer; Shape: TShape; begin for y := 0 to N-1 do for x := 0 to N-1 do begin snr := x +y *N +1; Shape := TShape(FindComponent('Shape' +IntToStr(snr))); if (Shape.Brush.Color = clBlack) then Feld[x, y] := True else Feld[x, y] := False; end;
end;
procedure TForm1.btnRechnenClick(Sender: TObject); var x, y: Integer; FeldNeu: TFeld; begin for y := 0 to N-1 do for x := 0 to N-1 do if Feld[x, y] then FeldNeu[x, y] := (AnzahlLebenderNachbarn(x, y) in [2..3]) else FeldNeu[x, y] := (AnzahlLebenderNachbarn(x, y) = 3); Feld := FeldNeu; btnSchreibenClick(Self); end; end. |
das könnte gut sein 
|
|
Narses
      

Beiträge: 10183
Erhaltene Danke: 1256
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: So 15.03.15 17:32
Moin!
Soo, dann gehen wir erstmal hier noch dran:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
| function TForm1.LebtNachbar(x, y: Integer): Boolean; begin if (x < 0) then x := x +N; if (y < 0) then y := y +N; if (x > (N-1)) then x := x -N; if (y > (N-1)) then y := y -N; Result := Feld[x, y]; end; |
Der markierte Teil "gefällt" mir noch nicht.  (ist nicht falsch, nur ... unschön)
Boldar hat schonmal drauf hingewiesen, es gibt die Modulo-Rechnung. Was war das nochmal?
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Nini 
      
Beiträge: 170
Erhaltene Danke: 12
|
Verfasst: So 15.03.15 18:35
bei x mod y wird nur der rest bei der division von x durch y angegeben
irgendwie hab ich das gefühl, dass das programm bei 5 feldern macht was es will, eigentlich muss ja so ein balken aus drei feldern sich immer drehn aber der verschwindet einfach -.-
|
|
Narses
      

Beiträge: 10183
Erhaltene Danke: 1256
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: So 15.03.15 18:50
Moin!
Nini hat folgendes geschrieben : | bei x mod y wird nur der rest bei der division von x durch y angegeben |
Richtig. Wir haben da also ein x, und das soll nur Werte zwischen 0..(N-1) annehmen können. Wie müsste man das dann mit mod schreiben?
Nini hat folgendes geschrieben : | irgendwie hab ich das gefühl, dass das programm bei 5 feldern macht was es will, eigentlich muss ja so ein balken aus drei feldern sich immer drehn aber der verschwindet einfach -.- |
Kontrollier mal die Reihenfolge der Shapes (also der Reihe nach eins im Formular anklicken und dann schauen, welche Nummer das hat - da könnte was schief gelaufen sein).
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Nini 
      
Beiträge: 170
Erhaltene Danke: 12
|
Verfasst: So 15.03.15 19:00
ok, danke  daran hat es wohl gelegen ..
ich vermute, dass das x MOD (N-1) sein müsste
|
|
Narses
      

Beiträge: 10183
Erhaltene Danke: 1256
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: So 15.03.15 19:11
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Nini 
      
Beiträge: 170
Erhaltene Danke: 12
|
Verfasst: So 15.03.15 19:16
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10:
| x | x mod N ------------ 0 |0 1 |1 2 |2 3 |3 4 |4 5 |5 6 |1 17 |2 |
|
|
Narses
      

Beiträge: 10183
Erhaltene Danke: 1256
W10ent
TP3 .. D7pro .. D10.2CE
|
Verfasst: So 15.03.15 19:21
Moin!
Danke, ist aber leider (nicht ganz, aber genug) falsch.
Kommen wir also wieder zu unserem Test-Button (das kennst du ja schon, Button auf´s Formular klatschen, doppelklicken, loslegen):
Delphi-Quelltext 1: 2: 3: 4:
| procedure TForm1.btnTestClick(Sender: TObject); begin ShowMessageFmt('x=%d, N=%d, x mod N=%d', [0, 5, 0 mod 5]); end; |
Damit mal bitte testen gehen...
cu
Narses
_________________ There are 10 types of people - those who understand binary and those who don´t.
|
|
Nini 
      
Beiträge: 170
Erhaltene Danke: 12
|
Verfasst: So 15.03.15 19:27
da kommt dann: x=0, N=5, x MOD N=0
|
|