summaryrefslogtreecommitdiff
path: root/slnnunit1.pas
diff options
context:
space:
mode:
Diffstat (limited to 'slnnunit1.pas')
-rw-r--r--slnnunit1.pas161
1 files changed, 161 insertions, 0 deletions
diff --git a/slnnunit1.pas b/slnnunit1.pas
new file mode 100644
index 0000000..51f600c
--- /dev/null
+++ b/slnnunit1.pas
@@ -0,0 +1,161 @@
+unit SLNNunit1;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+ Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
+ NNUnit;
+
+type
+
+ { TForm1 }
+
+ TBeispiel = record
+ Schl: Boolean;
+ _Br,_Ho,
+ WasIstGut: Integer;
+ Felder,
+ Kanten: Array of Byte;
+ end;
+
+ TForm1 = class(TForm)
+ Button1: TButton;
+ Memo1: TMemo;
+ OpenDialog1: TOpenDialog;
+ SaveDialog1: TSaveDialog;
+ procedure Button1Click(Sender: TObject);
+ procedure FormCreate(Sender: TObject);
+ procedure FormResize(Sender: TObject);
+ private
+ { private declarations }
+ public
+ { public declarations }
+ LernSatz: Array of TBeispiel;
+ function LadeLernSatz(Nam: String): Boolean;
+ end;
+
+var
+ Form1: TForm1;
+
+implementation
+
+{$R *.lfm}
+
+{ TForm1 }
+
+procedure TForm1.FormResize(Sender: TObject);
+begin
+ Memo1.Width:=Form1.ClientWidth - 2*Memo1.Left;
+ Memo1.Height:=Form1.ClientHeight - Memo1.Left - Memo1.Top;
+end;
+
+procedure TForm1.Button1Click(Sender: TObject);
+var I: Longint;
+begin
+ if OpenDialog1.Execute then
+ for I:=0 to OpenDialog1.Files.Count-1 do
+ if not LadeLernSatz(OpenDialog1.Files[I]) then
+ MessageDlg('Datei '''+OpenDialog1.Files[I]+''' ist ungültig!',mtError,[mbOk],0);
+end;
+
+procedure TForm1.FormCreate(Sender: TObject);
+begin
+ Setlength(LernSatz,0);
+end;
+
+function TForm1.LadeLernSatz(Nam: String): Boolean;
+var F: File;
+ B: Byte;
+ J,Gr: Longint;
+ Schleife: Boolean;
+ _Breite,
+ _Hoehe: Integer;
+ Eimer: Array of Array[0..4] of Integer;
+ Daten: Array[Boolean] of Array of Byte;
+// Input,
+// Output: TLongintArray;
+begin
+ Result:=false;
+ if not FileExists(Nam) then exit;
+ Setlength(Eimer,0);
+ AssignFile(F,Nam);
+ Reset(F,1);
+ B:=0;
+ _Breite:=1;
+ _Hoehe:=1;
+ while not eof(F) do begin
+ BlockRead(F,B,1);
+ if B>1 then begin
+ CloseFile(F);
+ exit;
+ end;
+ Schleife:=B=1;
+ if eof(F) then begin
+ CloseFile(F);
+ exit;
+ end;
+ BlockRead(F,_Breite,4);
+ if eof(F) then begin
+ CloseFile(F);
+ exit;
+ end;
+ BlockRead(F,_Hoehe,4);
+ J:=0;
+ while J<length(Eimer) do begin
+ if (Eimer[J,0]=Byte(Schleife)) and
+ (Eimer[J,1]=_Hoehe) and
+ (Eimer[J,2]=_Breite) then begin
+ inc(Eimer[J,3]);
+ break;
+ end;
+ inc(J);
+ end;
+ if J>=length(Eimer) then begin
+ setlength(Eimer,length(Eimer)+1);
+ Eimer[J,0]:=Byte(Schleife);
+ Eimer[J,1]:=_Hoehe;
+ Eimer[J,2]:=_Breite;
+ Eimer[J,3]:=1;
+ end;
+ Setlength(Daten[false],2*(_Breite-Byte(not Schleife)+1)*(_Hoehe-Byte(not Schleife)+1)-2); // Kanten
+ Setlength(Daten[true],(_Breite-Byte(not Schleife)+1)*(_Hoehe-Byte(not Schleife))-1); // Felder
+ for J:=0 to 1 do begin
+ if eof(F) then begin
+ CloseFile(F);
+ exit;
+ end;
+ BlockRead(F,Daten[J=1,0],length(Daten[J=1]));
+ end;
+ if eof(F) then begin
+ CloseFile(F);
+ exit;
+ end;
+ BlockRead(F,J,4);
+ SetLength(LernSatz,length(LernSatz)+1);
+ with LernSatz[length(LernSatz)-1] do begin
+ Schl:=Schleife;
+ _Br:=_Breite;
+ _Ho:=_Hoehe;
+ WasIstGut:=J;
+ SetLength(Kanten,length(Daten[false]));
+ for J:=0 to length(Kanten)-1 do
+ Kanten[J]:=Daten[false,J];
+ SetLength(Felder,length(Daten[true]));
+ for J:=0 to length(Felder)-1 do
+ Felder[J]:=Daten[true,J];
+ end;
+ end;
+ Closefile(F);
+ for J:=0 to length(Eimer)-1 do
+ Memo1.Lines.Add(inttostr(Eimer[J,0])+' '+inttostr(Eimer[J,1])+' '+inttostr(Eimer[J,2])+' '+inttostr(Eimer[J,3]));
+ Gr:=0;
+ for J:=0 to length(LernSatz)-1 do
+ Gr:=Gr+length(LernSatz[J].Kanten)+length(LernSatz[J].Felder);
+ Memo1.Lines.Add(inttostr(length(LernSatz))+' Beispiele insgesamt ('+floattostr((length(LernSatz)*sizeOf(TBeispiel)+Gr)/1024/1024)+'MB)');
+ Result:=true;
+end;
+
+end.
+