# Computer Chess Club Archives

## Messages

### Subject: Re: Negascout == PVS (with references)

Author: Stuart Cracraft

Date: 07:05:48 08/03/04

Go up one level in this thread

```FUNCTION PVS (p : position; alpha, beta, depth : integer ) : integer;
{ p is pointer to the current node     }
{ alpha and beta are window bounds     }
{ depth is the remaining search length }
{ the value of the subtree is returned }
VAR score, j, value : integer;
posn : ARRAY [1..MXWIDTH] OF position;
{ Note: depth must be positive }
BEGIN
IF depth = 0 THEN                         { horizon node, maximum depth? }
Return(Evaluate(p));

posn := Generate(p);                      { point to successor positions }
IF empty(posn) THEN                                    { leaf, no moves? }
Return(Evaluate(p));
{ principal variation? }
score :- -PVS (posn, -beta, -alpha, depth-1 );
FOR j := 2 TO sizeof(posn) DO BEGIN
IF (score >= beta) THEN                                      { cutoff? }
GOTO done;
alpha := max(score, alpha);                      { fail-soft condition }
{ zero-width minimal-window search }
value := -PVS (posn[j], -alpha-1, -alpha, depth-1);
IF (value > score) THEN                    { re-search, if "fail-high" }
IF (alpha < value) AND (value < beta) AND (depth > 2) THEN
score := -PVS (posn[j], -beta, -value, depth-1);
ELSE score := value;
END ;
done:
Return(score);

In looking at this PVS and comparing what I use I see I am researching
without the depth > 2 condition. Are these extra searches slowing me
down a lot? I can certainly put that in and try it out.

FUNCTION PVS (p : position; alpha, beta, depth : integer ) : integer;
{ p is pointer to the current node     }
{ alpha and beta are window bounds     }
{ depth is the remaining search length }
{ the value of the subtree is returned }
VAR score, j, value : integer;
posn : ARRAY [1..MXWIDTH] OF position;
{ Note: depth must be positive }
BEGIN
IF depth = 0 THEN                         { horizon node, maximum depth? }
Return(Evaluate(p));

posn := Generate(p);                      { point to successor positions }
IF empty(posn) THEN                                    { leaf, no moves? }
Return(Evaluate(p));
{ principal variation? }
score :- -PVS (posn, -beta, -alpha, depth-1 );
FOR j := 2 TO sizeof(posn) DO BEGIN
IF (score >= beta) THEN                                      { cutoff? }
GOTO done;
alpha := max(score, alpha);                      { fail-soft condition }
{ zero-width minimal-window search }
value:= -PVS (posn[j], -alpha-1, -alpha, depth-1);
IF (value > alpha && value < beta)
score:= -PVS (posn[j], -beta, -value, depth-1);
ELSE IF (value > score) THEN
score = value;
END ;
done:
Return(score);

```