PDA

نسخه کامل مشاهده نسخه کامل : خطایابی سورس هشت وزیر به زبان پاسکال



salehfard
09-12-2006, 22:23
این سورس را از همین قسمت گرفتم کی می تونه خطاشو در بیاره اگه بمن بگه که درستش کنم ممنون می شم
procedure ListEightQueenPositions;
var
Queens: array[1..8] of Integer; (* Holds the column number of each queen *)
NumPos: Integer;
Q, N: Integer;
SafePos: Boolean;
begin
(* Set position of all queens to undefined *)
for Q := 1 to 8 do
Queens[Q] := 0;
(* Set the number of found positions to zero *)
NumPos := 0;
(* Start by positioning the first queen *)
Q := 1;
(* While there's any possible position *)
while (Q <> 1) or (Queens[1] <> 8) do
begin
SafePos := False;
(* while a non-conflict position for the current queen has not found *)
while (Queens[Q] < 8) and not SafePos do
begin
(* Advance one colume the position of the queen *)
Queens[Q] := Queens[Q] + 1;
(* Check whether this column has any confilict with the the other queens *)
SafePos := True;
N := 1;
while (N < Q) and SafePos do
begin
(* Two queens are not in confilict with each other when *)
SafePos :=
(* They are not on the same column, and *)
(Queens[N] <> Queens[Q]) and
(* They are not on the same oblique line *)
(Abs(Queens[N] - Queens[Q]) <> Abs(N - Q));
(* Check with another queen *)
N := N + 1;
end;
end;
(* If there was a non-coflict position for the current queen *)
if SafePos then
begin
(* If it is the last queen *)
if Q = 8 then
begin
(* Increase the number of found positions by one *)
NumPos := NumPos + 1;
(* Print out the position of queens *)
Write(NumPos:2, ' -> ');
for N := 1 to 8 do
Write('(', N:1, ',', Queens[N]:1, ') ');
Writeln;
end
else
begin
(* Continue with the next queen *)
Q := Q + 1;
end;
end
else
begin
(* Set the position of the current queen undefined *)
Queens[Q] := 0;
(* Reposition the previous queen *)
Q := Q - 1;
end;
end;
end;

Payman_62
10-12-2006, 00:45
سلام.
لطفا سوالتون رو در بخش مربوطه مطرح کنید.