In the following code <moves> is in stack memory.
How can I best store the PV line at the place marked <STORE_PV>?
Can I get it from the stack?
Code: Select all
function tsearch.alphabeta(depth: integer; alpha, beta: tscore): tscore;
var
moves: tmovelist;
ms: pmovestack;
u: tstateinfo;
value: tscore;
m: tmove;
valid: integer;
label
exitpoint;
begin
if depth <= 0 then begin
result := quiet(alpha, beta);
if board.tomove = black then
result := -result;
exit;
end;
inc(searchdepth);
valid := 0;
board.genmoves(@moves);
ms := @moves[0];
while getnextmove(m) do begin
board.makemove(m, u);
inc(valid);
value := -alphabeta(depth - 1, -beta, -alpha);
board.unmakemove(m);
if value >= beta then begin
result := beta;
goto exitpoint;
end;
if value > alpha then begin
alpha := value;
if atroot then begin
bestmove := m;
bestscore := alpha;
STORE_PV()
end;
end;
inc(ms);
end;
if valid = 0 then begin
if board.isincheck then begin
result := -mate + searchdepth - 1;
end
else
result := drawscore();
end
else
result := alpha;
exitpoint:
dec(searchdepth);
end;
