組件設置 paintbox
繪圖板
顯示當前的合法布局
Label
文字標簽
顯示當前合法布局的序號
Button
button
button
button
開始
單幅
連續
退出按紐
程序清單
(
)代碼單元unit
procedure TForm
Button
Click(Sender: TObject);
begin
dstep:=true;
bhh:=tbhh
create(false);
button
enabled:=false;
button
enabled:=true;
button
enabled:=true;
end;
procedure TForm
Button
Click(Sender: TObject);
begin
if dstep=false then begin bhh
suspend; dstep:=true end
else bhh
resume
end;
procedure TForm
Button
Click(Sender: TObject);
begin
dstep:=false; bhh
resume;
end;
(
)代碼單元unit
uses unit
;
procedure Tbhh
Execute;
begin
hsu(
);
form
button
enabled:=true;
form
button
enabled:=false;
form
button
enabled:=false;
end;
procedure tbhh
prt;//顯示
var i
j
ix
iy:integer;
s:real;iis:string[
];
begin
str(tt:
iis);
form
label
caption:=
第
+iis+
幅
;
form
paintbox
canvas
draw(
q);
for i:=
to
do
for j:=
to
do
if a[i
j]=
then
begin
ix:=(i
)*
+
;
iy:=(j
)*
+
;
form
paintbox
canvas
draw(iy
ix
c);
end;
if dstep=true then suspend
else begin s:=
; for i:=
to
do s:=s*s/s end;
end;
procedure tbhh
hsu(i:integer);//回溯求解
var j:integer;
begin
if i>
then begin tt:=tt+
; synchronize(prt)end
else for j:=
to
do
begin a[i
j]:=
;if pd(i
j) then hsu(i+
);a[i
j]:=
;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:=
to
do
for j:=
to
do
a[i
j]:=
; tt:=
;
end;
end
[] []
From:http://tw.wingwit.com/Article/program/Delphi/201311/8515.html