futility pruining, razoring question

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

mar
Posts: 2559
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: futility pruining, razoring question

Post by mar »

lucasart wrote: You're right. As pointed out by Martin, I got fooled by the chess programming wiki :wink:
I'm currently testing this alternative:

Code: Select all

	if &#40;UseRazoring && depth <= RazorDepth
		&& !is_pv && !is_mate_score&#40;beta&#41; && !in_check&#41;
	&#123;
		if &#40;current_eval + RazorMargin&#40;depth&#41; <= alpha&#41; &#123;
			const int score = qsearch&#40;B, alpha, beta, 0, ply+1, is_pv, si+1&#41;;
			if &#40;score + RazorMargin&#40;depth&#41; <= alpha&#41;	//**
				return score;
		&#125;
	&#125;
I've just ran 1000 games in 6"+0.1", and it scored 52% against my previous code. Thanks for the tip!
Shouldn't that be

Code: Select all

	if &#40;UseRazoring && depth <= RazorDepth
		&& !is_pv && !is_mate_score&#40;beta&#41; && !in_check&#41;
	&#123;
		if &#40;current_eval + RazorMargin&#40;depth&#41; <= alpha&#41; &#123;
			const int score = qsearch&#40;B, alpha-RazorMargin&#40;depth&#41;, beta-RazorMargin&#40;depth&#41;, 0, ply+1, is_pv, si+1&#41;;
			if &#40;score <= alpha - RazorMargin&#40;depth&#41;)	//**
				return score;
		&#125;
	&#125;
instead? Because if you use fail-hard score will never get below alpha. So I guess your patch simply disables razoring.
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: futility pruining, razoring question

Post by lucasart »

mar wrote:
lucasart wrote: You're right. As pointed out by Martin, I got fooled by the chess programming wiki :wink:
I'm currently testing this alternative:

Code: Select all

	if &#40;UseRazoring && depth <= RazorDepth
		&& !is_pv && !is_mate_score&#40;beta&#41; && !in_check&#41;
	&#123;
		if &#40;current_eval + RazorMargin&#40;depth&#41; <= alpha&#41; &#123;
			const int score = qsearch&#40;B, alpha, beta, 0, ply+1, is_pv, si+1&#41;;
			if &#40;score + RazorMargin&#40;depth&#41; <= alpha&#41;
				return score;
		&#125;
	&#125;
I've just ran 1000 games in 6"+0.1", and it scored 52% against my previous code. Thanks for the tip!
Shouldn't that be

Code: Select all

	if &#40;UseRazoring && depth <= RazorDepth
		&& !is_pv && !is_mate_score&#40;beta&#41; && !in_check&#41;
	&#123;
		if &#40;current_eval + RazorMargin&#40;depth&#41; <= alpha&#41; &#123;
			const int score = qsearch&#40;B, alpha-RazorMargin&#40;depth&#41;, beta-RazorMargin&#40;depth&#41;, 0, ply+1, is_pv, si+1&#41;;
			if &#40;score <= alpha - RazorMargin&#40;depth&#41;)
				return score;
		&#125;
	&#125;
instead? Because if you use fail-hard score will never get below alpha. So I guess your patch simply disables razoring.
I use fail soft, so it's not equivalent to switching off the razoring. Anyway, I'm currently testing your suggestion (modify the qsearch bounds)
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: futility pruining, razoring question

Post by mcostalba »

lucasart wrote: I use fail soft, so it's not equivalent to switching off the razoring. Anyway, I'm currently testing your suggestion (modify the qsearch bounds)
Martin is correct, even with soft-fail you shouldn't trust the value of any score outside alpha, beta window: it gives only a very light added indication above the real important info that search failed low.
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: futility pruining, razoring question

Post by lucasart »

mcostalba wrote:
lucasart wrote: I use fail soft, so it's not equivalent to switching off the razoring. Anyway, I'm currently testing your suggestion (modify the qsearch bounds)
Martin is correct, even with soft-fail you shouldn't trust the value of any score outside alpha, beta window: it gives only a very light added indication above the real important info that search failed low.
Yes, it was a silly mistake indeed. Corrected code is scoring 54% against previous version at fast time control (200k nodes per move, 1k games). A nice bugfix :D
rbarreira
Posts: 900
Joined: Tue Apr 27, 2010 3:48 pm

Re: futility pruining, razoring question

Post by rbarreira »

mcostalba wrote:
lucasart wrote: I use fail soft, so it's not equivalent to switching off the razoring. Anyway, I'm currently testing your suggestion (modify the qsearch bounds)
Martin is correct, even with soft-fail you shouldn't trust the value of any score outside alpha, beta window: it gives only a very light added indication above the real important info that search failed low.
The problem in Lucas's first code was not that it was trusting a score outside the search window. The problem was that it was using the wrong search window in the first place, and expecting fail-soft to return the exact score outside that window. Of course fail-soft does not guarantee to return exact scores outside the window, otherwise it would be called minimax.

But when fail-soft does return a value outside the window, you should indeed trust it unless you have code that returns scores outside the window which are speculatively high or low (which is not a good idea). The correct approach is to only return a score as high or as low as you know to be accurate. If that means having to return alpha/beta at certain specific places in the code, that's quite OK even in fail-soft.
diep
Posts: 1822
Joined: Thu Mar 09, 2006 11:54 pm
Location: The Netherlands

Re: futility pruining, razoring question

Post by diep »

mar wrote:
lucasart wrote: You're right. As pointed out by Martin, I got fooled by the chess programming wiki :wink:
I'm currently testing this alternative:

Code: Select all

	if &#40;UseRazoring && depth <= RazorDepth
		&& !is_pv && !is_mate_score&#40;beta&#41; && !in_check&#41;
	&#123;
		if &#40;current_eval + RazorMargin&#40;depth&#41; <= alpha&#41; &#123;
			const int score = qsearch&#40;B, alpha, beta, 0, ply+1, is_pv, si+1&#41;;
			if &#40;score + RazorMargin&#40;depth&#41; <= alpha&#41;	//**
				return score;
		&#125;
	&#125;
I've just ran 1000 games in 6"+0.1", and it scored 52% against my previous code. Thanks for the tip!
Shouldn't that be

Code: Select all

	if &#40;UseRazoring && depth <= RazorDepth
		&& !is_pv && !is_mate_score&#40;beta&#41; && !in_check&#41;
	&#123;
		if &#40;current_eval + RazorMargin&#40;depth&#41; <= alpha&#41; &#123;
			const int score = qsearch&#40;B, alpha-RazorMargin&#40;depth&#41;, beta-RazorMargin&#40;depth&#41;, 0, ply+1, is_pv, si+1&#41;;
			if &#40;score <= alpha - RazorMargin&#40;depth&#41;)	//**
				return score;
		&#125;
	&#125;
instead? Because if you use fail-hard score will never get below alpha. So I guess your patch simply disables razoring.
the code looks like a crappy form of razoring. Razoring on alpha you need a huge margin. I remember Ed Schroeder was using 10 pawns there in some code he posted a few years ago.

Try razoring on beta, then you can use just 1 pawn or 1.5 pawn or so as a margin.
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: futility pruining, razoring question

Post by lucasart »

diep wrote:
mar wrote:
lucasart wrote: You're right. As pointed out by Martin, I got fooled by the chess programming wiki :wink:
I'm currently testing this alternative:

Code: Select all

	if &#40;UseRazoring && depth <= RazorDepth
		&& !is_pv && !is_mate_score&#40;beta&#41; && !in_check&#41;
	&#123;
		if &#40;current_eval + RazorMargin&#40;depth&#41; <= alpha&#41; &#123;
			const int score = qsearch&#40;B, alpha, beta, 0, ply+1, is_pv, si+1&#41;;
			if &#40;score + RazorMargin&#40;depth&#41; <= alpha&#41;	//**
				return score;
		&#125;
	&#125;
I've just ran 1000 games in 6"+0.1", and it scored 52% against my previous code. Thanks for the tip!
Shouldn't that be

Code: Select all

	if &#40;UseRazoring && depth <= RazorDepth
		&& !is_pv && !is_mate_score&#40;beta&#41; && !in_check&#41;
	&#123;
		if &#40;current_eval + RazorMargin&#40;depth&#41; <= alpha&#41; &#123;
			const int score = qsearch&#40;B, alpha-RazorMargin&#40;depth&#41;, beta-RazorMargin&#40;depth&#41;, 0, ply+1, is_pv, si+1&#41;;
			if &#40;score <= alpha - RazorMargin&#40;depth&#41;)	//**
				return score;
		&#125;
	&#125;
instead? Because if you use fail-hard score will never get below alpha. So I guess your patch simply disables razoring.
the code looks like a crappy form of razoring. Razoring on alpha you need a huge margin. I remember Ed Schroeder was using 10 pawns there in some code he posted a few years ago.

Try razoring on beta, then you can use just 1 pawn or 1.5 pawn or so as a margin.
What are you talking about ?
At non PV nodes, alpha == beta - 1
At PV nodes, I don't do razoring
diep
Posts: 1822
Joined: Thu Mar 09, 2006 11:54 pm
Location: The Netherlands

Re: futility pruining, razoring question

Post by diep »

I take arbitrary values now which are not too stupid and i write it in clumsy code to make it more understandable and you should do too, instead of use source code that just adds to the fuzz:

alpha razoring:

Code: Select all

if&#40; depthleft <= 3 && eval <= alpha + 10 pawns ) return eval;
beta razoring:

Code: Select all

if&#40; depthleft <= 3 && eval >= beta - 1.5 pawn ) return eval;
Of course you execute this everywhere. PV or not doesn't matter, so there is a big difference between alpha and beta potentially. Using extra assumptions is not a good manner to post it.

If you want to expand the razoring to be more accurate on alpha, you can of course replace eval there with qsearch. But why bother if you already were razoring the previous searches that all populate the hashtable anyway, using qsearch then just is eating precious system time you don't want to waste...

Just razor it bigtime :)

Either you use razoring or not at all i'd say :)

Just go play games with it, tad slower time control and compare with your initial implementation. Don't do superbullet; at superbullet being tactical stronger works.
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: futility pruining, razoring question

Post by mcostalba »

diep wrote:using qsearch then just is eating precious system time you don't want to waste...
You must use qsearch otherwise you could return fail-low score and perhaps you are one move away from capturing enemy queen. Note that on what you call beta razoring (and I call static null move pruning) you don't need the qsearch to validate the result.

BTW alpha razoring on PV node is non-sense.

Ohh, another thing, your code is plain wrong, you messed up the signs, you may wanted to write alpha - 10 pawns and beta +1,5 pawns.

Ohh, indeed even another thing, alpha - 10 pawns is useless, it is like to stay at home at night becuase going outside you risk to take a cold or to meet bad guys :-)
diep
Posts: 1822
Joined: Thu Mar 09, 2006 11:54 pm
Location: The Netherlands

Re: futility pruining, razoring question

Post by diep »

Indeed small sign problem hereby corrected and we see
directly why it is important to keep things simple:

Code to razor at TOP of the position:

Code: Select all

if&#40; depthleft <= 3 && eval <= alpha - QueenValue - 1 pawn ) return eval;
beta razoring:
Code:

Code: Select all

if&#40; depthleft <= 3 && eval >= beta + 1.5 pawn ) return eval;
Oh by the way the 10 pawn window for alpha was used by Ed,
i'd be very careful razoring on alpha indeed as you correctly warn,
yet i would start testing the above and do without qsearch first.

Only after that test WITH qsearch. It's trivial to test all combinations there though i'd say...

In Diep razoring doesn't work at all.

Note that positional COMPENSATION (not to confuse with the grand total) in total can easily add up to 50 pawns in Diep. By just grabbing some of the big bonuses/penalties,
and throw those in a 'quickeval' in Diep i can get in 99% of the cases to the full evaluation within 3 pawns actually.

Yet it's that 1% that's outside that is so important and decides how strong Diep actually plays :)

Nevertheless, if you razor, your hashtables will be so total overloaded and give cutoffs everywhere also to refute moves that otherwise would make it to the mainline, especially if you search in parallel, that you better can razor in a drastic manner IMHO if you do it at all.