Mate Score

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Mate Score

Post by hgm »

JVMerlino wrote:If you allow the King to capture a piece in SEE, then isn't a very high King value necessary?
SEE usually has its own piece values, not necessarily equivalent to those in search. But also there you have to add special code for detecting King capture, to avoid King trading. At least, if you also do X-rays. e.g.

[d]8/8/8/8/R2Kpk2/7r/8/8 w

would have SEE = +1 for Kxe4 irrespective of the King value. It must be taught explicitly that after KxP, KxK it cannot continue with RxK to get ahead again.
tomitank
Posts: 276
Joined: Sat Mar 04, 2017 12:24 pm
Location: Hungary

Re: Mate Score

Post by tomitank »

Stockfish 8 use this:

Code: Select all

 
  VALUE_MATE      = 32000,
  VALUE_INFINITE  = 32001,
  VALUE_NONE      = 32002,

  VALUE_MATE_IN_MAX_PLY  =  VALUE_MATE - 2 * MAX_PLY,
  VALUE_MATED_IN_MAX_PLY = -VALUE_MATE + 2 * MAX_PLY,

Code: Select all

inline Value mated_in(int ply) {
  return -VALUE_MATE + ply;
}

Code: Select all

 
Value value_to_tt(Value v, int ply) {

    assert(v != VALUE_NONE);

    return  v >= VALUE_MATE_IN_MAX_PLY  ? v + ply
          &#58; v <= VALUE_MATED_IN_MAX_PLY ? v - ply &#58; v;
  &#125;

Code: Select all

  Value value_from_tt&#40;Value v, int ply&#41; &#123;

    return  v == VALUE_NONE             ? VALUE_NONE
          &#58; v >= VALUE_MATE_IN_MAX_PLY  ? v - ply
          &#58; v <= VALUE_MATED_IN_MAX_PLY ? v + ply &#58; v;
  &#125;

Code: Select all

string UCI&#58;&#58;value&#40;Value v&#41; &#123;

  stringstream ss;

  if &#40;abs&#40;v&#41; < VALUE_MATE - MAX_PLY&#41;
      ss << "cp " << v * 100 / PawnValueEg;
  else
      ss << "mate " << &#40;v > 0 ? VALUE_MATE - v + 1 &#58; -VALUE_MATE - v&#41; / 2;

  return ss.str&#40;);
&#125;
---------------------------------------------------------------------------

If i use this:

Code: Select all

#define MAXDEPTH 64 // max Ply equal
#define INFINITE 30000
#define ISMATE &#40;INFINITE - MAXDEPTH * 2&#41;

// Mate
return -INFINITE + boardPly;

function isMate&#40;Score&#41; &#123;
	return Score >= ISMATE || Score <= -ISMATE;
&#125;
is it still wrong?
User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Mate Score

Post by hgm »

If MAX_PLY is the maximum search depth, and could be realistically reached, it is still wrong. If in practice search depth will always stay very much below MAX_PLY, you will probably get away with it.


The system of encoding mate scores and evaluations on the same scale of 16-bit numbers will always limit the maximum mate distance that can be indicated. It seems unlikely, however, that the engine will ever be able to find a mate deeper than mate in 8000. So why not use codes -24,000 to 24,000 to indicate evaluation scores, and 24,000 to 32,000 for mate scores?

Of course it is a bit questionable whether you really want the engine to prefer, say, a mate-in-1000 over a (heuristic evaluation) score of 20,000 milli-Pawns. Even though you have no mathematical prove of the mate, would it really be conceivable that with such a lead it would take more than 1000 ply to force checkmate?
tomitank
Posts: 276
Joined: Sat Mar 04, 2017 12:24 pm
Location: Hungary

Re: Mate Score

Post by tomitank »

If MAX_PLY is the maximum search depth, and could be realistically reached, it is still wrong. If in practice search depth will always stay very much below MAX_PLY, you will probably get away with it.
Sorry, that's missed:
I have in "AlphaBeta" and in Qsearch this code:

Code: Select all

if &#40;boardPly > maxDepth - 1&#41; &#123;
	return Evaluation&#40;);
&#125;
User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Mate Score

Post by hgm »

Sure. But if maxDepth is one million, it is not likely this line will ever be triggered. And it is also quite unlikely you will ever to be able to find a mate-in-8000, no matter how large maxDepth is.
tomitank
Posts: 276
Joined: Sat Mar 04, 2017 12:24 pm
Location: Hungary

Re: Mate Score

Post by tomitank »

All right. I understand.

Thanks H.G. Muller! :)

Tamas
User avatar
Kotlov
Posts: 266
Joined: Fri Jul 10, 2015 9:23 pm
Location: Russia

Re: Mate Score

Post by Kotlov »

my code is

Code: Select all

 I&#40;n&#41;I&#40;z&#41;R y-IF;E O
:D