PV test and PVS

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

MOBMAT
Posts: 385
Joined: Sat Feb 04, 2017 11:57 pm
Location: USA

PV test and PVS

Post by MOBMAT »

I'm debugging a run time error in some new code and found a situation that isn't intuitive.

entering a node i apply the PV test...

Code: Select all

bool bIsPV = (alpha != beta - 1);
in this test example, alpha = 123 and beta is 124, so, bIsPV is false, indication we are not in the PV

entering the move loop, the first move available is made, bumping the MoveCount variable from 0 to 1 and then we reach the PVS code. I coded the PVS code to what I "thought" was the correct way to do it, so....

Code: Select all

if (MoveCount == 1) {	// haven't searched yes, so PV
	v = -ABTTFH(&p1, -beta, -alpha, NewDepth, &cPV, NM::NM_ALLOWED);
	}
else	{
	v = -ABTTFH(&p1, -alpha - 1, -alpha, NewDepth, &cPV, NM::NM_ALLOWED);
		if ((v > alpha) && (v < beta))
		v = -ABTTFH(&p1, -beta, -alpha, NewDepth, &cPV, NM::NM_ALLOWED);
	}
Now wait a minute. the bIsPV test says we aren't in the PV, but the logic for the PVS indicates that the first move should be search full width. Which is correct? Should the PVS code actually read...

Code: Select all

if (bIsPV) {	// whether we are trying the first move or not...
	v = -ABTTFH(&p1, -beta, -alpha, NewDepth, &cPV, NM::NM_ALLOWED);
	}
else	{
	v = -ABTTFH(&p1, -alpha - 1, -alpha, NewDepth, &cPV, NM::NM_ALLOWED);
		if ((v > alpha) && (v < beta))
		v = -ABTTFH(&p1, -beta, -alpha, NewDepth, &cPV, NM::NM_ALLOWED);
	}
is the bIsPV test 100% accurate?
i7-6700K @ 4.00Ghz 32Gb, Win 10 Home, EGTBs on PCI SSD
Benchmark: Stockfish15.1 NNUE x64 bmi2 (nps): 1277K
elcabesa
Posts: 855
Joined: Sun May 23, 2010 1:32 pm

Re: PV test and PVS

Post by elcabesa »

this is my simplfied code for PVS

Code: Select all

if(PVnode)
{
	if(moveNumber==1)
	{
		val = -alphaBeta( -beta, -alpha );
	}
	else
	{
		val = -alphaBeta( -alpha-1, -alpha);
		if( val > alpha && val < beta )
		{
			val = -alphaBet( -beta, -alpha );
		}
	}
}
else
{
	val = -alphaBeta( -alpha-1, -alpha );
}
MOBMAT
Posts: 385
Joined: Sat Feb 04, 2017 11:57 pm
Location: USA

Re: PV test and PVS

Post by MOBMAT »

and do you use the same method that I described to determine if (PVNode) is true?

I'm not sure I've seen this representation of PVS code.
I am referencing the "node type" page
https://chessprogramming.wikispaces.com ... s#PV-Nodes
so,

Code: Select all

if(PVnode) {
	if(moveNumber==1) { //The first child of a PV-node is a PV-node, so search wide
		val = -alphaBeta( -beta, -alpha );
	}
	else { // The further children are searched by a scout search as CUT-nodes, so search zero windowsw
		val = -alphaBeta( -alpha-1, -alpha);
		if( val > alpha && val < beta ) { // PVS re-search is done as PV-node, so search wide
			val = -alphaBet( -beta, -alpha );
		}
	}
}
else {
	val = -alphaBeta( -alpha-1, -alpha ); //non PVNODES are cut-nodes, so search narrow (1)
}		  	

(1) so on deeper nodes, it appears they can never be PV NODES again, is that true?
i7-6700K @ 4.00Ghz 32Gb, Win 10 Home, EGTBs on PCI SSD
Benchmark: Stockfish15.1 NNUE x64 bmi2 (nps): 1277K
elcabesa
Posts: 855
Joined: Sun May 23, 2010 1:32 pm

Re: PV test and PVS

Post by elcabesa »

MOBMAT wrote: Sat Jun 09, 2018 12:30 am and do you use the same method that I described to determine if (PVNode) is true?
not the same code but equivalent

Code: Select all

if(PVnode) {
	if(moveNumber==1) { //The first child of a PV-node is a PV-node, so search wide
		val = -alphaBeta( -beta, -alpha );
	}
	else { // The further children are searched by a scout search as CUT-nodes, so search zero windowsw
		val = -alphaBeta( -alpha-1, -alpha);
		if( val > alpha && val < beta ) { // PVS re-search is done as PV-node, so search wide
			val = -alphaBet( -beta, -alpha );(2)
		}
	}
}
else {
	val = -alphaBeta( -alpha-1, -alpha ); //non PVNODES are cut-nodes, so search narrow (1)
}		  	

(1) so on deeper nodes, it appears they can never be PV NODES again, is that true?
if a deeper node result is not failing low it will make fail his father, and so on until a (2) fail and the tree is researched as PV node.

only the child of a PV can be PV, a child of CUT orALL nodes cannot be PV
User avatar
hgm
Posts: 27791
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: PV test and PVS

Post by hgm »

If you don't re-search when the score of the null-window ('scout') search is >= beta, then there is no need to treat PV nodes different from others. Non-PV nodes then will never perform a re-search, as the only way for later moves to score > alpha automatically scores >= beta if the node had a null-window to start with.

Scores above beta when beta != alpha+1 can only occur in a fail-soft framework, though. An even there then will occur only very rarely; as alpha-beta search is based on not wasting time to prove the score is better than you need, it will indeed harly ever do so.
User avatar
xr_a_y
Posts: 1871
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Re: PV test and PVS

Post by xr_a_y »

And here comes the stupid question : how to implement PVS if score is float and not int ?
elcabesa
Posts: 855
Joined: Sun May 23, 2010 1:32 pm

Re: PV test and PVS

Post by elcabesa »

xr_a_y wrote: Sat Jun 09, 2018 4:04 pm And here comes the stupid question : how to implement PVS if score is float and not int ?
I don't know, I asked it to myself too.

fixed point alpha beta has some beautiful properties ( i.e. null windows -> beta= alpha+1 ), floating point is a little trickier, you have to be really careful with > >= != end so on
elcabesa
Posts: 855
Joined: Sun May 23, 2010 1:32 pm

Re: PV test and PVS

Post by elcabesa »

hgm wrote: Sat Jun 09, 2018 4:00 pm If you don't re-search when the score of the null-window ('scout') search is >= beta, then there is no need to treat PV nodes different from others. Non-PV nodes then will never perform a re-search, as the only way for later moves to score > alpha automatically scores >= beta if the node had a null-window to start with.

Scores above beta when beta != alpha+1 can only occur in a fail-soft framework, though. An even there then will occur only very rarely; as alpha-beta search is based on not wasting time to prove the score is better than you need, it will indeed harly ever do so.
you are right, but I like to have a clear code that some year later i can still understand, anbd this implementation is a little verbose but clear
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: PV test and PVS

Post by Sven »

xr_a_y wrote: Sat Jun 09, 2018 4:04 pm And here comes the stupid question : how to implement PVS if score is float and not int ?
This should be unrelated to PVS, you will have many places in your engine where you compare two scores. And here comes the stupid answer: just don't do it :-) Use integer scores representing centipawns, 1/256 pawns, millipawns, 1/1024 pawns, whatever you like.

However, if you really insist ... Check out google-test, I once read that they have a nice implementation for floating point comparison.
Sven Schüle (engine author: Jumbo, KnockOut, Surprise)
User avatar
xr_a_y
Posts: 1871
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Re: PV test and PVS

Post by xr_a_y »

:oops: :oops: :oops: TODO: make Weini use int instead of float ... :? :? :?