benvining wrote: ↑Sat Jun 07, 2025 10:14 pmShould the mate score be smaller than the absolute max of the Eval data type?
Typically, your range would look like this - only shown for the positive range here:
0 ... EVAL_MAX ... MAX
The range 0-EVAL_MAX is what you can get in game play, assuming weird things like all base pieces plus eight queen promoted pawns against a king and a shielding pawn. What I mean is the static evaluation of that position, not the mate related one.
[d]k2qqrrq/4bbnn/6qq/6qq/6qq/8/7P/7K w - - 0 1
And then you'd score a mate position (i.e. a mate in 0) with MAX. For each ply to get to that position, you subtract the ply count so that a mate in 1 would be MAX-1, mate in 2 MAX-3 and so on. This way, you make sure that your engine actually goes for a mate instead of merely detecting it and then shuffling around.
Now, a GUI shouldn't transmit a mate position (i.e. mate in 0) because there are no legal moves, that's the definition of a mate. But you can easily sort that out before starting the search if you want. The kicker is that even if the best move does deliver mate, that'll be scored as MAX-1. Your initial window, however, starts with MAX.
Note that you'll also need to take care of mate scores in your transposition table with translating back and forth betwen root-relative and node-relative mate scores. Because what was, say, a mate-in-2 in this move becomes a mate-in-1 in the next move from the GUI.
Also, you'd transmit scores differently depending on the range. In UCI, you'd use "score cp" in the 0 ... EVAL_MAX range, but "score mate" in the EVAL_MAX ... MAX range - properly adjusted, of course.