Razoring

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Razoring

Post by lucasart »

I did a few experiments with Razoring, and would like to share some results.

my first attempt at razoring was:

Code: Select all

	// Razoring
	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 <= alpha && --depth <= 0&#41;
				return score;
		&#125;
	&#125;
So, when all the usual pre-conditions are met, I reduced if qsearch failed low. With this method, I've found that it's best to reduce rather than prune. I lost the actual result of my self-play test, but I remember that they were clear as day. It's probably because this approach is flawed, and puts too much trust in the qsearch.

So I then did like everyone else (Hyatt Razoring) and compared qsearch to alpha - RazorMargin(depth) instead. However, I still wanted to test reducing against pruning in this situation. And I found that reducing is actually *better* than pruning. Result in self-testing: 321-249-297 (stopped by sequential Wald test algorithm).

Hyat Razoring & Reduce

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 razor_beta = beta - RazorMargin&#40;depth&#41;;
			const int score = qsearch&#40;B, alpha, beta, 0, ply+1, is_pv, si+1&#41;;
			if &#40;score <= razor_beta
				&& --depth <= 0&#41;	// reduce
				return score;		// prune at horizon
		&#125;
	&#125;
Hyat Razoring & Prune

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 razor_beta = beta - RazorMargin&#40;depth&#41;;
			const int score = qsearch&#40;B, alpha, beta, 0, ply+1, is_pv, si+1&#41;;
			if &#40;score <= razor_beta&#41;
				return score;
		&#125;
	&#125;
I wonder if other engine developers have tested it, and whether or not they came to the same conclusion. In theory, reducing is safer than pruning, so even if the elo gain is zero this modification could be added on the basis that it should improve (slightly) the results in tactical test suites.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Razoring

Post by bob »

lucasart wrote:I did a few experiments with Razoring, and would like to share some results.

my first attempt at razoring was:

Code: Select all

	// Razoring
	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 <= alpha && --depth <= 0&#41;
				return score;
		&#125;
	&#125;
So, when all the usual pre-conditions are met, I reduced if qsearch failed low. With this method, I've found that it's best to reduce rather than prune. I lost the actual result of my self-play test, but I remember that they were clear as day. It's probably because this approach is flawed, and puts too much trust in the qsearch.

So I then did like everyone else (Hyatt Razoring) and compared qsearch to alpha - RazorMargin(depth) instead. However, I still wanted to test reducing against pruning in this situation. And I found that reducing is actually *better* than pruning. Result in self-testing: 321-249-297 (stopped by sequential Wald test algorithm).

Hyat Razoring & Reduce

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 razor_beta = beta - RazorMargin&#40;depth&#41;;
			const int score = qsearch&#40;B, alpha, beta, 0, ply+1, is_pv, si+1&#41;;
			if &#40;score <= razor_beta
				&& --depth <= 0&#41;	// reduce
				return score;		// prune at horizon
		&#125;
	&#125;
Hyat Razoring & Prune

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 razor_beta = beta - RazorMargin&#40;depth&#41;;
			const int score = qsearch&#40;B, alpha, beta, 0, ply+1, is_pv, si+1&#41;;
			if &#40;score <= razor_beta&#41;
				return score;
		&#125;
	&#125;
I wonder if other engine developers have tested it, and whether or not they came to the same conclusion. In theory, reducing is safer than pruning, so even if the elo gain is zero this modification could be added on the basis that it should improve (slightly) the results in tactical test suites.
Where does that "hyatt code" come from? It does not appear to look anything like the code in recent Crafty versions... I don't do "razoring" at all. I prune or reduce...
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: Razoring

Post by lucasart »

bob wrote:
lucasart wrote:I did a few experiments with Razoring, and would like to share some results.

my first attempt at razoring was:

Code: Select all

	// Razoring
	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 <= alpha && --depth <= 0&#41;
				return score;
		&#125;
	&#125;
So, when all the usual pre-conditions are met, I reduced if qsearch failed low. With this method, I've found that it's best to reduce rather than prune. I lost the actual result of my self-play test, but I remember that they were clear as day. It's probably because this approach is flawed, and puts too much trust in the qsearch.

So I then did like everyone else (Hyatt Razoring) and compared qsearch to alpha - RazorMargin(depth) instead. However, I still wanted to test reducing against pruning in this situation. And I found that reducing is actually *better* than pruning. Result in self-testing: 321-249-297 (stopped by sequential Wald test algorithm).

Hyat Razoring & Reduce

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 razor_beta = beta - RazorMargin&#40;depth&#41;;
			const int score = qsearch&#40;B, alpha, beta, 0, ply+1, is_pv, si+1&#41;;
			if &#40;score <= razor_beta
				&& --depth <= 0&#41;	// reduce
				return score;		// prune at horizon
		&#125;
	&#125;
Hyat Razoring & Prune

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 razor_beta = beta - RazorMargin&#40;depth&#41;;
			const int score = qsearch&#40;B, alpha, beta, 0, ply+1, is_pv, si+1&#41;;
			if &#40;score <= razor_beta&#41;
				return score;
		&#125;
	&#125;
I wonder if other engine developers have tested it, and whether or not they came to the same conclusion. In theory, reducing is safer than pruning, so even if the elo gain is zero this modification could be added on the basis that it should improve (slightly) the results in tactical test suites.
Where does that "hyatt code" come from? It does not appear to look anything like the code in recent Crafty versions... I don't do "razoring" at all. I prune or reduce...
i found it in the chess programming wiki, under the name Hyatt Razoring.
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: Razoring

Post by lucasart »

lucasart wrote:
bob wrote:
lucasart wrote:I did a few experiments with Razoring, and would like to share some results.

my first attempt at razoring was:

Code: Select all

	// Razoring
	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 <= alpha && --depth <= 0&#41;
				return score;
		&#125;
	&#125;
So, when all the usual pre-conditions are met, I reduced if qsearch failed low. With this method, I've found that it's best to reduce rather than prune. I lost the actual result of my self-play test, but I remember that they were clear as day. It's probably because this approach is flawed, and puts too much trust in the qsearch.

So I then did like everyone else (Hyatt Razoring) and compared qsearch to alpha - RazorMargin(depth) instead. However, I still wanted to test reducing against pruning in this situation. And I found that reducing is actually *better* than pruning. Result in self-testing: 321-249-297 (stopped by sequential Wald test algorithm).

Hyat Razoring & Reduce

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 razor_beta = beta - RazorMargin&#40;depth&#41;;
			const int score = qsearch&#40;B, alpha, beta, 0, ply+1, is_pv, si+1&#41;;
			if &#40;score <= razor_beta
				&& --depth <= 0&#41;	// reduce
				return score;		// prune at horizon
		&#125;
	&#125;
Hyat Razoring & Prune

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 razor_beta = beta - RazorMargin&#40;depth&#41;;
			const int score = qsearch&#40;B, alpha, beta, 0, ply+1, is_pv, si+1&#41;;
			if &#40;score <= razor_beta&#41;
				return score;
		&#125;
	&#125;
I wonder if other engine developers have tested it, and whether or not they came to the same conclusion. In theory, reducing is safer than pruning, so even if the elo gain is zero this modification could be added on the basis that it should improve (slightly) the results in tactical test suites.
Where does that "hyatt code" come from? It does not appear to look anything like the code in recent Crafty versions... I don't do "razoring" at all. I prune or reduce...
i found it in the chess programming wiki, under the name Hyatt Razoring.
http://www.talkchess.com/forum/viewtopic.php?t=24286
Gerd Isenberg
Posts: 2250
Joined: Wed Mar 08, 2006 8:47 pm
Location: Hattingen, Germany

Re: Razoring

Post by Gerd Isenberg »

bob wrote: Where does that "hyatt code" come from? It does not appear to look anything like the code in recent Crafty versions... I don't do "razoring" at all. I prune or reduce...
I coined Hyatt's Razoring in cpw, because you proposed it as mentioned by Lucas. Should I credit somebody else?
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: Razoring

Post by lucasart »

Gerd Isenberg wrote:
bob wrote: Where does that "hyatt code" come from? It does not appear to look anything like the code in recent Crafty versions... I don't do "razoring" at all. I prune or reduce...
I coined Hyatt's Razoring in cpw, because you proposed it as mentioned by Lucas. Should I credit somebody else?
the thread I mentionned suggests that it was Tord's idea in Glaurung in the first place.
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Razoring

Post by Sven »

lucasart wrote:
Gerd Isenberg wrote:
bob wrote: Where does that "hyatt code" come from? It does not appear to look anything like the code in recent Crafty versions... I don't do "razoring" at all. I prune or reduce...
I coined Hyatt's Razoring in cpw, because you proposed it as mentioned by Lucas. Should I credit somebody else?
the thread I mentionned suggests that it was Tord's idea in Glaurung in the first place.
I don't think so. It seems Bob had temporarily tried to insert very old Crafty razoring code into current Crafty (back in 2008) after he heard that Tord used razoring, and did some cluster testing to check whether that old code might improve Crafty 23.x. But the code quoted by Bob in that thread must be very old, it is not contained in any Crafty source version since 15.17 (from ~1998) available on the "cis.uab.edu" site. So there might be some misunderstanding around here. Nevertheless, the name "Hyatt razoring" does not appear to be completely wrong, only the century is missing ...

Sven
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: Razoring

Post by lucasart »

I was more hoping for a discussion on the *actual* topic... If anyone has done some actual testing and has something useful to say on this problem, feel free...

So let's just call it razoring i/o Hyatt razoring, and avoid these discussions about who invented the wheel and who first called it a wheel...
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Razoring

Post by mcostalba »

lucasart wrote: the thread I mentionned suggests that it was Tord's idea in Glaurung in the first place.
Yes it is a Tord's idea.

Perhaps now Bob says that in the 70' he tried already this in an experimental Cray computer in assembly, but it doesn't matter.....it is a Tord's idea.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Razoring

Post by bob »

Gerd Isenberg wrote:
bob wrote: Where does that "hyatt code" come from? It does not appear to look anything like the code in recent Crafty versions... I don't do "razoring" at all. I prune or reduce...
I coined Hyatt's Razoring in cpw, because you proposed it as mentioned by Lucas. Should I credit somebody else?
No, that was what I did a good while back. I thought he was looking at Crafty source, which doesn't do razoring any longer, resorting on actual forward pruning instead...