Witam. Mam problem z napisaniem algorytmu, który będzie sprawdzał wszystkie możliwości ruchu w grze kółko i krzyżyk. Chciałbym, aby po każdym warunku funkcja sprawdzała, czy dokonały się jakieś zmiany, a jak dokonały, żeby funkcja się przerwała. Na razie napisałem coś takiego, tylko głównym problemem jest to, że podczas przycisku danego speedbuttona program się całkowicie wiesza. Proszę o pomoc. Z góry dziekuje
function Tkolkoikrzyzyk.bot(n:integer):boolean;
var
wybor2:integer;
begin
wybor2:= random(9);
gracz2.down:=true;
while true do
begin
if ((p2.caption='x') and (p3.caption='x') and (p1.Caption='')) or
((p4.caption='x') and (p7.caption='x') and (p1.Caption='')) or
((p5.caption='x') and (p9.caption='x') and (p1.Caption=''))
{or ((wybor2= 0 )and (p1.caption='' )) } then
begin
p1Click(kolkoikrzyzyk);
break;
end;
if ((p1.caption='x') and (p3.caption='x') and (p2.Caption='')) or
((p5.caption='x') and (p8.caption='x') and (p2.Caption='')) {or
((p.caption='x') and (p9.caption='x') and (p2.Caption=''))} {or ((wybor2= 1 )and (p2.caption='' ))} then
begin
p2Click(kolkoikrzyzyk)
break;
end;
if ((p1.caption='x') and (p2.caption='x') and (p3.Caption='')) or
((p6.caption='x') and (p9.caption='x') and (p3.Caption='')) or
((p5.caption='x') and (p7.caption='x') and (p3.Caption='')) {or ((wybor2= 2 )and (p3.caption='' )) }then
begin
p3Click(kolkoikrzyzyk);
break;
end;
if ((p1.caption='x') and (p7.caption='x') and (p4.Caption='')) or
((p5.caption='x') and (p6.caption='x') and (p4.Caption='')) {or
((p5.caption='x') and (p9.caption='x') and (p4.Caption='')) }{or ((wybor2= 3 )and (p4.caption='' )) }then
begin
p4Click(kolkoikrzyzyk);
break;
end;
if ((p4.caption='x') and (p6.caption='x') and (p5.Caption='')) or
((p2.caption='x') and (p8.caption='x') and (p5.Caption='')) or
((p3.caption='x') and (p7.caption='x') and (p5.Caption='')){or ((wybor2= 4 )and (p5.caption='' )) }then
begin
p5Click(kolkoikrzyzyk);
break;
end;
if ((p4.caption='x') and (p5.caption='x') and (p6.Caption='')) or
((p3.caption='x') and (p9.caption='x') and (p6.Caption='')) or
((p1.caption='x') and (p9.caption='x') and (p6.Caption='')) {or ((wybor2= 5 )and (p6.caption='' )) }then
begin
p6Click(kolkoikrzyzyk);
break;
end;
if ((p8.caption='x') and (p9.caption='x') and (p7.Caption='')) or
((p4.caption='x') and (p1.caption='x') and (p7.Caption='')) or
((p5.caption='x') and (p3.caption='x') and (p7.Caption='')) {or ((wybor2= 6 )and (p7.caption='' ))}then
begin
p7Click(kolkoikrzyzyk);
break;
end;
if ((p7.caption='x') and (p9.caption='x') and (p8.Caption='')) or
((p2.caption='x') and (p5.caption='x') and (p8.Caption='')) {or
((p5.caption='x') and (p9.caption='x') and (p8.Caption='')) }{or ((wybor2= 7 )and (p8.caption='' )) }then
begin
p8Click(kolkoikrzyzyk);
break;
end;
if ((p7.caption='x') and (p8.caption='x') and (p9.Caption='')) or
((p3.caption='x') and (p6.caption='x') and (p9.Caption='')) or
((p1.caption='x') and (p5.caption='x') and (p9.Caption='')){or ((wybor2= 8 )and (p9.caption='' ))} then
begin
p9Click(kolkoikrzyzyk);
break;
end
else
//dla 0
if ((p2.caption='0') and (p3.caption='0') and (p1.Caption='')) or
((p4.caption='0') and (p7.caption='0') and (p1.Caption='')) or
((p5.caption='0') and (p9.caption='0') and (p1.Caption='')){or ((wybor2= 0 )and (p1.caption='' )) } then
begin
p1Click(kolkoikrzyzyk);
break;
end;
if ((p1.caption='0') and (p3.caption='0') and (p2.Caption='')) or
((p5.caption='0') and (p8.caption='0') and (p2.Caption='')) {or
((p.caption='x') and (p9.caption='x') and (p2.Caption=''))} {or ((wybor2= 1 )and (p2.caption='' ))} then
begin
p2Click(kolkoikrzyzyk);
break;
end;
if ((p1.caption='0') and (p2.caption='0') and (p3.Caption='')) or
((p6.caption='0') and (p9.caption='0') and (p3.Caption='')) or
((p5.caption='0') and (p7.caption='0') and (p3.Caption='')) {or ((wybor2= 2 )and (p3.caption='' )) } then
begin
p3Click(kolkoikrzyzyk);
break;
end;
if ((p1.caption='0') and (p7.caption='0') and (p4.Caption='')) or
((p5.caption='0') and (p6.caption='0') and (p4.Caption='')) {or
((p5.caption='0') and (p9.caption='0') and (p4.Caption='')) }{or ((wybor2= 3 )and (p4.caption='' )) }then
begin
p4Click(kolkoikrzyzyk);
break;
end;
if ((p4.caption='0') and (p6.caption='0') and (p5.Caption='')) or
((p2.caption='0') and (p8.caption='0') and (p5.Caption='')) or
((p3.caption='0') and (p7.caption='0') and (p5.Caption='')){or ((wybor2= 4 )and (p5.caption='' )) }then
begin
p5Click(kolkoikrzyzyk);
break;
end;
if ((p4.caption='0') and (p5.caption='0') and (p6.Caption='')) or
((p3.caption='0') and (p9.caption='0') and (p6.Caption='')) or
((p1.caption='0') and (p9.caption='0') and (p6.Caption='')) {or ((wybor2= 5 )and (p6.caption='' )) }then
begin
p6Click(kolkoikrzyzyk);
break;
end;
if ((p8.caption='0') and (p9.caption='0') and (p7.Caption='')) or
((p4.caption='0') and (p1.caption='0') and (p7.Caption='')) or
((p5.caption='0') and (p3.caption='0') and (p7.Caption='')) {or ((wybor2= 6 )and (p7.caption='' ))}then
begin
p7Click(kolkoikrzyzyk);
break;
end;
if ((p7.caption='0') and (p9.caption='0') and (p8.Caption='')) or
((p2.caption='0') and (p5.caption='0') and (p8.Caption='')) {or
((p5.caption='0') and (p9.caption='0') and (p8.Caption='')) }{or ((wybor2= 7 )and (p8.caption='' )) }then
begin
p8Click(kolkoikrzyzyk);
break;
end;
if ((p7.caption='0') and (p8.caption='0') and (p9.Caption='')) or
((p3.caption='0') and (p6.caption='0') and (p9.Caption='')) or
((p1.caption='0') and (p5.caption='0') and (p9.Caption='')){or ((wybor2= 8 )and (p9.caption='' ))} then
begin
p9Click(kolkoikrzyzyk);
break;
end;
if ((wybor2= 0 )and (p1.caption='' ))then
begin
p1.caption:='0' ;
end;
if ((wybor2= 1 )and (p2.caption='' ))then
begin
p2.caption:='0' ;
end;
if ((wybor2= 2 )and (p3.caption='' ))then
begin
p3.caption:='0' ;
break;
end;
if ((wybor2= 3 )and (p4.caption='' ))then
begin
p4.caption:='0' ;
break;
end;
if ((wybor2= 4 )and (p5.caption='' ))then
begin
p5.caption:='0' ;
break;
end;
if ((wybor2= 5 )and (p6.caption='' ))then
begin
p6.caption:='0' ;
break;
end;
if ((wybor2= 6 )and (p7.caption='' ))then
begin
p7.caption:='0' ;
break;
end;
if ((wybor2= 7 )and (p8.caption='' ))then
begin
p8.caption:='0' ;
break;
end;
if ((wybor2= 8 )and (p9.caption='' ))then
begin
p9.caption:='0' ;
break;
end;
end;
gracz1.Down:=true;
end;