uses unit1; procedure Tbhh.Execute; begin hsu(1); form1.button1.enabled:=true; form1.button2.enabled:=false; form1.button3.enabled:=false; end;
procedure tbhh.prt;//显示 var i,j,ix,iy:integer; s:real;iis:string[2]; begin str(tt:2,iis); form1.label1.caption:='第'+iis+'幅'; form1.paintbox1.canvas.draw(0,0,q); for i:=1 to 8 do for j:=1 to 8 do if a[i,j]=1 then begin ix:=(i-1)*50+1; iy:=(j-1)*50+1; form1.paintbox1.canvas.draw(iy,ix,c); end; if dstep=true then suspend else begin s:=10; for i:=1 to 100000 do s:=s*s/s end; end; procedure tbhh.hsu(i:integer);//回溯求解 var j:integer; begin if i>8 then begin tt:=tt+1; synchronize(prt)end else for j:=1 to 8 do begin a[i,j]:=1;if pd(i,j) then hsu(i+1);a[i,j]:=0;end end; constructor tbhh.create(flag:boolean);//创建该线程的一实例并对有关的变量进行初始化 var i,j:integer; begin inherited create(flag); q:=tbitmap.create;q.loadfromfile('e:/八皇后/backing.bmp'); c:=tbitmap.create;c.loadfromfile('e:/八皇后/queen.bmp'); for i:=1 to 8 do for j:=1 to 8 do a[i,j]:=0; tt:=0; end; end. |