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
|
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.
|