Помогите разобраться программном коде программы Искусственный интеллект, время очень поджимает. unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, XPMan;
type
TForm1 = class(TForm)
GroupBox1: TGroupBox;
Memo1: TMemo;
GroupBox2: TGroupBox;
Edit1: TEdit;
XPManifest1: TXPManifest;
procedure FormCreate(Sender: TObject);
procedure Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
type
TKeyWord = record
key,answer : string;
end;
const AnswersCount = 310;
var
GeneratedFraza : string='';
Answers : array [1..AnswersCount] of TKeyWord;
Dialog : array [1..20] of string;
Hi : array [1..7] of string;
Form1: TForm1;
implementation
{$R *.dfm}
function FindAnswer(text : string) : boolean;
var
i,count : integer;
ans : array [0..10] of integer;
begin
count:=0;
for i:=1 to AnswersCount do
begin
if Answers[i].key=text then
begin
ans[count]:=i;
inc(count);
end;
end;
if count<>0 then
begin
randomize;
result:=true;
GeneratedFraza:='Кибер разум: '+Answers[ans[random(count)]].answer;
end else result:=false;
end;
procedure LetAnswer(text : string);
var
i,found : integer;
slovo : string;
probel : boolean;
begin
slovo :='';
probel:=false;
found:=0;
for i:=1 to length(text) do
begin
if text[i]=' ' then probel:=true;
if not probel then begin
slovo:=slovo+text[i];
if findanswer(lowercase(slovo)) then inc(found);
end else begin slovo:=''; probel:=false; end;
end;
if found=0 then
form1.Memo1.Lines.Add('Кибер разум: '+dialog[random(20)+1]) else
form1.Memo1.Lines.Add(GeneratedFraza);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
s : Tstringlist;
i,a : integer;
f : string;
done : boolean;
begin
if not fileexists(ExtractFilepath(Application.ExeName)+'Mozgi.brain') then
begin
Showmessage('Ôàéë ñ ìîçãàìè "Mozgi.brain" íå áûë íàéäåí, áåç íåãî ïðîãà ðàáîòàòü íå áóäåò.');
Close;
end;
s:=Tstringlist.Create;
s.LoadFromFile(ExtractFilepath(Application.ExeName)+'Mozgi.brain');
for i:=1 to AnswersCount do
begin
f:=lowercase(s.Strings[i-1]);
answers[i].key:='';
answers[i].answer:=s.ValueFromIndex[i-1];
done:=false;
for a:=1 to length(f) do
begin
if f[a]='=' then done:=true;
if not done then Answers[i].key:=Answers[i].key+f[a];
end;
end;
for i:=1 to 20 do dialog[i]:=s.ValueFromIndex[i+AnswersCount];
for i:=1 to 7 do hi[i]:=s.ValueFromIndex[i+AnswersCount+21];
randomize;
memo1.Lines.Add('Êèáåð ðàçóì: '+hi[1+random(7)]);
end;
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (key=vk_return) and (Edit1.Text<>'') then
begin
Memo1.Lines.Add('Þçåð: '+Edit1.Text);
LetAnswer(lowercase(Edit1.Text));
Edit1.Text:='';
end;
end;
end.