熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Delphi編程 >> 正文

基於Delphi的“八皇後”問題動態實現[2]

2022-06-13   來源: Delphi編程 

  組件設置

  paintbox繪圖板顯示當前的合法布局

  Label文字標簽顯示當前合法布局的序號

  Buttonbuttonbuttonbutton開始單幅連續退出按紐

  程序清單

  ()代碼單元unit

procedure TFormButtonClick(Sender: TObject);
begin
 dstep:=true;
 bhh:=tbhhcreate(false);
 buttonenabled:=false;
 buttonenabled:=true;
 buttonenabled:=true;
end;

procedure TFormButtonClick(Sender: TObject);
begin
 if dstep=false then begin bhhsuspend; dstep:=true end
 else bhhresume
end;

procedure TFormButtonClick(Sender: TObject);
begin
 dstep:=false; bhhresume;
end;
  ()代碼單元unit

uses unit;
procedure TbhhExecute;
begin
 hsu();
 formbuttonenabled:=true;
 formbuttonenabled:=false;
 formbuttonenabled:=false;
end;

procedure tbhhprt;//顯示
 var ijixiy:integer;
 s:real;iis:string[];
begin
 str(tt:iis);
 formlabelcaption:=+iis+;
 formpaintboxcanvasdraw(q);
 for i:= to do
  for j:= to do
   if a[ij]= then
   begin
    ix:=(i)*+;
    iy:=(j)*+;
    formpaintboxcanvasdraw(iyixc);
   end;
   if dstep=true then suspend
   else begin s:=; for i:= to do s:=s*s/s end;
  end;
  procedure tbhhhsu(i:integer);//回溯求解
  var j:integer;
  begin
   if i> then begin tt:=tt+; synchronize(prt)end
   else for j:= to do
   begin a[ij]:=;if pd(ij) then hsu(i+);a[ij]:=;end
  end;
  constructor tbhhcreate(flag:boolean);//創建該線程的一實例並對有關的變量進行初始化
 var ij:integer;
 begin
  inherited create(flag);
  q:=tbitmapcreate;qloadfromfile(e:\八皇後\backingbmp);
  c:=tbitmapcreate;cloadfromfile(e:\八皇後\queenbmp);
  for i:= to do
   for j:= to do
    a[ij]:=; tt:=;
   end;
  end

[]  []  


From:http://tw.wingwit.com/Article/program/Delphi/201311/8515.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.