if not RestoreLastSolution then
Begin
Assignfile(Input, 'D:\Работы по ОАиП\Курсовая работа\Формы(без стека)\Placements.txt');
Rewrite(Input);
Stack := TStack<Integer>.Create;
Solution := TStack<Integer>.Create;
End;
if RestoreLastSolution then
Begin
//Solution := TStack<Integer>.Create;
Stack := Solution;
End;
if RestoreLastSolution then
Begin
x := StrToInt(S[1];
Y := StrToInt(S[2]);
End;
if RestoreLastSolution then
Begin
x := 1;
Y := StrToInt(S[2]);
End;
procedure StackSolution(RestoreLastSolution: boolean);
var
i, j, Y, x: Integer;
a: array [1 .. MaxQueensCount] of Boolean;
b: array [2 .. 2 * MaxQueensCount] of Boolean;
c: array [1 - MaxQueensCount .. MaxQueensCount - 1] of Boolean;
Stack: TStack<Integer>;
SolutionArray: TArray<Integer>;
s: string;
flag1, flag2: boolean;
Function Uspeh: Boolean;
Var
usp: Boolean;
Begin
usp := False;
While (Y < QueensCount) And Not usp do
Begin
Y := Y + 1;
usp := a[Y] and b[x + Y] and c[Y - x];
End;
Result := usp;
End;
begin
if not RestoreLastSolution then
begin
For i := 1 to QueensCount do
a[i] := True;
For i := 2 to 2 * QueensCount do
b[i] := True;
For i := 1 - QueensCount to QueensCount - 1 do
c[i] := True;
end;
if RestoreLastSolution then
begin
Assignfile(Input, 'D:\Работы по ОАиП\Курсовая работа\Формы(без стека)\Placements.txt');
Reset(Input);
while (not EOF(Input)) do begin
Readln(Input, s);
end;
CloseFile(Input);
For i := 1 to QueensCount do
if S[I]='T' then a[i] := True
else a[i] := False;
Delete(S,1,QueensCount+1);
For i := 2 to 2 * QueensCount do
if S[I]='T' then b[i] := True
else b[i] := False;
Delete(S,1,2 * QueensCount);
For i := 1 - QueensCount to QueensCount - 1 do
if S[I]='T' then c[i] := True
else c[i] := False;
Delete(S,1,QueensCount+QueensCount-1);
end;
Assignfile(Input, 'D:\Работы по ОАиП\Курсовая работа\Формы(без стека)\Placements.txt');
Rewrite(Input);
Stack := TStack<Integer>.Create;
try
if not RestoreLastSolution then
Begin
x := 1;
Y := 0;
End;
if RestoreLastSolution then
Begin
x := StrToInt(S[1]);
Y := StrToInt(S[2]);
End;
while (x <> 0) and not StopPressed do
Begin
If Uspeh Then
Begin
Stack.Push(Y);
If x < QueensCount Then
Begin
a[Y] := False;
b[x + Y] := False;
c[Y - x] := False;
x := x + 1;
Y := 0;
End
Else
begin
if not RestoreLastSolution then
Begin
For I := 1 to QueensCount do
begin
if A[I] then
write(Input, 'T')
else
write(Input, 'F')
End;
write(Input,'|');
For i := 2 to 2 * QueensCount do
begin
if B[I] then
write(Input, 'T')
else
write(Input, 'F')
End;
write(Input,'|');
For i := 1 - QueensCount to QueensCount - 1 do
Begin
if C[I] then
write(Input, 'T')
else
write(Input, 'F')
End;
write(Input, X, Y);
writeln(Input);
End;
frmMain.DrawSolution(Stack);
Stack.Pop;
end;
End
Else
Begin
x := x - 1;
If x > 0 Then
Begin
Y := Stack.Pop;
a[Y] := True;
b[x + Y] := True;
c[Y - x] := True;
End;
End;
End;
Closefile(Input);
finally
Stack.Free;
End;
End;
procedure TfrmMain.Button2Click(Sender: TObject);
begin
StopPressed := False;
Fla:=False;
StackSolution();
end;
procedure StackSolution;
var
i, Y, x: Integer;
a: array [1 .. MaxQueensCount] of Boolean;
b: array [2 .. 2 * MaxQueensCount] of Boolean;
c: array [1 - MaxQueensCount .. MaxQueensCount - 1] of Boolean;
Stack: TStack<Integer>;
SolutionArray: TArray<Integer>;
s: string;
Function Uspeh: Boolean;
Var
usp: Boolean;
Begin
usp := False;
While (Y < QueensCount) And Not usp do
Begin
Y := Y + 1;
usp := a[Y] and b[x + Y] and c[Y - x];
End;
Result := usp;
End;
begin
Fla:=True;
For i := 1 to QueensCount do
a[i] := True;
For i := 2 to 2 * QueensCount do
b[i] := True;
For i := 1 - QueensCount to QueensCount - 1 do
c[i] := True;
if not Fla then
Begin
Assignfile(Input, 'D:\Работы по ОАиП\Курсовая работа\Формы(без стека)\Placements.txt');
Reset(Input);
while (not EOF(Input)) do begin
Readln(Input, s);
end;
CloseFile(Input);
for I := 1 to QueensCount do
if s[i] in ['0'..'9'] then SolutionArray[i - 1]:=StrToInt(s[i]);
End;
Stack := TStack<Integer>.Create;
try
x := 1;
Y := 0;
while (x <> 0) and not StopPressed do
Begin
If Uspeh Then
Begin
Stack.Push(Y);
If x < QueensCount Then
Begin
a[Y] := False;
b[x + Y] := False;
c[Y - x] := False;
x := x + 1;
Y := 0;
End
Else
begin
frmMain.DrawSolution(Stack);
Stack.Pop;
end;
End
Else
Begin
x := x - 1;
If x > 0 Then
Begin
Y := Stack.Pop;
a[Y] := True;
b[x + Y] := True;
c[Y - x] := True;
End;
End;
End;
finally
Stack.Free;
End;
End;
Я сохраняю решение последнее, потом снова всё на true, потом восстанавливаю решение, а вот как передать в рекурсию с того же значения?