Null returning mate

Discussion of chess software programming and technical issues.

Moderators: hgm, Harvey Williamson, bob

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Post Reply
outAtime
Posts: 226
Joined: Sun Mar 08, 2009 2:08 pm
Location: Canada

Null returning mate

Post by outAtime » Thu Dec 09, 2010 5:41 am

Hi, Im having some trouble with having mate scores returned, and the engine resigning or playing a terrible move. Im guessing its because I dont have anything to tell Null move not to return a mate score...

Code: Select all

if (null_score >= beta && depth > 5)
			{	
       	    
			    null_score = -search(beta, alpha, depth - 5, TRUE); 
				
				if (null_score >= beta)
                return beta; 
            }
            else
            {
			
            if (null_score >= beta)
			
            return beta;
			
			if &#40;null_score < -INF + 10 * maxdepth&#41;
				extensions++;
		    &#125;		
Ive seen sections in other programs, but im not sure how to define...

an example from fruit:

Code: Select all

 if &#40;value >= beta&#41; &#123;

            if &#40;value > +ValueEvalInf&#41; value = +ValueEvalInf; // do not return unproven mates
            ASSERT&#40;!value_is_mate&#40;value&#41;);
so i need to define +ValueEvalInf, and !value_is_mate. Im guessing +ValueEvalInf should = +INF but im not certain about what value_is_mate should be (INF - 100 ? )

stockfish code looks a bit simpler:

Code: Select all

if &#40;nullValue >= beta&#41;
        &#123;
            // Do not return unproven mate scores
            if &#40;nullValue >= value_mate_in&#40;PLY_MAX&#41;)
                nullValue = beta;
but again... im having trouble how to define value_mate_in(PLY_MAX)

The other possible problem is that in move ordering the PV is scored highest at INF... I wonder if I need to drop that lower, hash for example is INF - 10000. Thanks.
outAtime

User avatar
Desperado
Posts: 635
Joined: Mon Dec 15, 2008 10:45 am

Re: Null returning mate

Post by Desperado » Thu Dec 09, 2010 9:27 am

hi kenny,

i am pretty sure you figured it out by yourself already, but anyway...

you have a window with [loBound,hiBound], as example [-30000,30000].
you also have defined somewhere your maxHeight you will search for.
as example maxHeight=256

so finally the mate scores are:

mated_in: loBound+maxHeight (-30000+256)
mate_in : hiBound-maxHeight ( 30000- 256)

Further, i suggest only return scores from evaluation or from search itself.
dont mix _sortValues_ with _evaluationValues_.So you can easily work with different ranges in your move ordering scheme.
As example historyScores can be 128000...

regards

outAtime
Posts: 226
Joined: Sun Mar 08, 2009 2:08 pm
Location: Canada

Re: Null returning mate

Post by outAtime » Thu Dec 09, 2010 2:11 pm

Nothing seems to be working, Ive tried a bunch of ideas but Im still getting mate scores... This wasn't happening before so Ill have to check the code for some kind of bug. I don't think I have height defined, unless that is max_depth or something.

Code: Select all

/* result flags&#58; */
#define no_result      0
#define stalemate      1
#define white_is_mated 2
#define black_is_mated 3
#define draw_by_fifty  4
#define draw_by_rep    5

/* hash flags&#58; */
#define no_info    0
#define avoid_null 1
#define exact      2
#define u_bound    3
#define l_bound    4

Code: Select all

/* adjust our score if it is a mate score&#58; */
		if &#40;abs&#40;score&#41; > INF - 100&#41; &#123;
			if &#40;score > 0&#41;
				score -= &#40;ply&#41;;
			else
				score += &#40;ply&#41;;
		&#125;
Thanks.
outAtime

bob
Posts: 20346
Joined: Mon Feb 27, 2006 6:30 pm
Location: Birmingham, AL

Re: Null returning mate

Post by bob » Thu Dec 09, 2010 8:14 pm

outAtime wrote:Hi, Im having some trouble with having mate scores returned, and the engine resigning or playing a terrible move. Im guessing its because I dont have anything to tell Null move not to return a mate score...

Code: Select all

if &#40;null_score >= beta && depth > 5&#41;
			&#123;	
       	    
			    null_score = -search&#40;beta, alpha, depth - 5, TRUE&#41;; 
				
				if &#40;null_score >= beta&#41;
                return beta; 
            &#125;
            else
            &#123;
			
            if &#40;null_score >= beta&#41;
			
            return beta;
			
			if &#40;null_score < -INF + 10 * maxdepth&#41;
				extensions++;
		    &#125;		
Ive seen sections in other programs, but im not sure how to define...

an example from fruit:

Code: Select all

 if &#40;value >= beta&#41; &#123;

            if &#40;value > +ValueEvalInf&#41; value = +ValueEvalInf; // do not return unproven mates
            ASSERT&#40;!value_is_mate&#40;value&#41;);
so i need to define +ValueEvalInf, and !value_is_mate. Im guessing +ValueEvalInf should = +INF but im not certain about what value_is_mate should be (INF - 100 ? )

stockfish code looks a bit simpler:

Code: Select all

if &#40;nullValue >= beta&#41;
        &#123;
            // Do not return unproven mate scores
            if &#40;nullValue >= value_mate_in&#40;PLY_MAX&#41;)
                nullValue = beta;
but again... im having trouble how to define value_mate_in(PLY_MAX)

The other possible problem is that in move ordering the PV is scored highest at INF... I wonder if I need to drop that lower, hash for example is INF - 10000. Thanks.
First question, are you doing null-move searches when the side playing the null move is in check? If so, don't. If you mean the opposite side (from one playing null) returns a mate, that is perfectly OK, and should cause the null-move search to fail low and be discarded...

Then you just do a normal search to find a way to avoid the mate.

bob
Posts: 20346
Joined: Mon Feb 27, 2006 6:30 pm
Location: Birmingham, AL

Re: Null returning mate

Post by bob » Thu Dec 09, 2010 8:18 pm

outAtime wrote:Nothing seems to be working, Ive tried a bunch of ideas but Im still getting mate scores... This wasn't happening before so Ill have to check the code for some kind of bug. I don't think I have height defined, unless that is max_depth or something.

Code: Select all

/* result flags&#58; */
#define no_result      0
#define stalemate      1
#define white_is_mated 2
#define black_is_mated 3
#define draw_by_fifty  4
#define draw_by_rep    5

/* hash flags&#58; */
#define no_info    0
#define avoid_null 1
#define exact      2
#define u_bound    3
#define l_bound    4

Code: Select all

/* adjust our score if it is a mate score&#58; */
		if &#40;abs&#40;score&#41; > INF - 100&#41; &#123;
			if &#40;score > 0&#41;
				score -= &#40;ply&#41;;
			else
				score += &#40;ply&#41;;
		&#125;
Thanks.
That looks correct if you are talking about the score you _store_ via hashing. As when you look up the entry and retrieve the hash score, you then have to add ply back in since you store mates as "mate in N from current position" and if you are 5 plies into the search, then it is a mate in N+3.

For a normal mate score, which is found when the current side is in check, and has no legal moves, I return -mate + ply where -mate is a large constant. That works everywhere when you detect you are mated, assuming you use negamax.

outAtime
Posts: 226
Joined: Sun Mar 08, 2009 2:08 pm
Location: Canada

Re: Null returning mate

Post by outAtime » Thu Dec 09, 2010 8:33 pm

Yes, thankyou. So I have this now and everything appears to be functioning as it should.

Code: Select all

if &#40;no_moves&#41; &#123;
		if &#40;in_check&#40;)) &#123;
			alpha = -INF + ply;
		&#125; else &#123;
			alpha = 0;
		&#125;
	&#125; else ... check 50 move rule

Code: Select all

/* check to see if we can get a quick cutoff from our null move&#58; */
			if &#40;null_score >= beta&#41;
			&#123;	
       	        if &#40;null_score >= INF - 100&#41;
                null_score = beta;
				
				if &#40;depth < 6&#41; 
				return beta; 
				
			    null_score = -search&#40;beta, alpha, depth - 5, FALSE&#41;; 
				
				if &#40;null_score >= beta&#41;				
                return beta; 
            &#125;
            else
            &#123;
				
			if &#40;null_score < -INF + 10 * maxdepth&#41;
				extensions++;
		    &#125;		
		&#125;
	&#125;
Everything seems ok... until I mess up the next thing ;)
outAtime

bob
Posts: 20346
Joined: Mon Feb 27, 2006 6:30 pm
Location: Birmingham, AL

Re: Null returning mate

Post by bob » Thu Dec 09, 2010 8:41 pm

outAtime wrote:Yes, thankyou. So I have this now and everything appears to be functioning as it should.

Code: Select all

if &#40;no_moves&#41; &#123;
		if &#40;in_check&#40;)) &#123;
			alpha = -INF + ply;
		&#125; else &#123;
			alpha = 0;
		&#125;
	&#125; else ... check 50 move rule

Code: Select all

/* check to see if we can get a quick cutoff from our null move&#58; */
			if &#40;null_score >= beta&#41;
			&#123;	
       	        if &#40;null_score >= INF - 100&#41;
                null_score = beta;
				
				if &#40;depth < 6&#41; 
				return beta; 
				
			    null_score = -search&#40;beta, alpha, depth - 5, FALSE&#41;; 
				
				if &#40;null_score >= beta&#41;				
                return beta; 
            &#125;
            else
            &#123;
				
			if &#40;null_score < -INF + 10 * maxdepth&#41;
				extensions++;
		    &#125;		
		&#125;
	&#125;
Everything seems ok... until I mess up the next thing ;)
We all do it from time to time. I've screwed up repetition detection more than any other person on the planet I am certain...

User avatar
JVMerlino
Posts: 932
Joined: Wed Mar 08, 2006 9:15 pm
Location: San Francisco, California

Re: Null returning mate

Post by JVMerlino » Thu Dec 09, 2010 8:53 pm

bob wrote:We all do it from time to time. I've screwed up repetition detection more than any other person on the planet I am certain...
If I end up programming chess engines for as long as you have, Bob, I'm sure I'll break your record. Of course, the worst part is finding out about these kinds of bugs while watching your engine lose an important won game -- happened twice to me already (once with rep detection and once with egtb implementation).

Live and (hopefully) learn....

jm

bob
Posts: 20346
Joined: Mon Feb 27, 2006 6:30 pm
Location: Birmingham, AL

Re: Null returning mate

Post by bob » Thu Dec 09, 2010 10:30 pm

JVMerlino wrote:
bob wrote:We all do it from time to time. I've screwed up repetition detection more than any other person on the planet I am certain...
If I end up programming chess engines for as long as you have, Bob, I'm sure I'll break your record. Of course, the worst part is finding out about these kinds of bugs while watching your engine lose an important won game -- happened twice to me already (once with rep detection and once with egtb implementation).

Live and (hopefully) learn....

jm
In my case it is fun to watch your score climb to +8, +10, and then suddenly you see a draw claim and the game ends, and your program had no clue. :)

Working perfectly today, thankfully, although I am sure there must be something else that needs assistance...

Post Reply