When Stockfish (or any other strong engine) plays it often gives a "0.00" draw score — sometimes in the middlegame. It's unlikely an evaluation function would come out exactly at 0.00. How does Stockfish do this?
In the early days of NNUE we had win-loss-draw probabilities. Is the evaluation assumed to be 0.00 if the draw probability is above a certain threshold?
— Steve
Q: How to Detect a Draw?
Moderators: hgm, Rebel, chrisw
-
- Posts: 1231
- Joined: Wed Mar 08, 2006 8:28 pm
- Location: Florida, USA
Q: How to Detect a Draw?
http://www.chessprogramming.net - Maverick Chess Engine
-
- Posts: 11779
- Joined: Thu Mar 09, 2006 12:57 am
- Location: Birmingham UK
Re: Q: How to Detect a Draw?
I'm going to take a guess for fun: is it that these middle game positions are actually far enough advanced that the search is terminating in all branches of the game tree in positions that are known to be drawn?
The simple reveals itself after the complex has been exhausted.
-
- Posts: 27965
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: Q: How to Detect a Draw?
Well, for one the chances are not that small. Many of the games are not yet decided at that point, and 1% of the scores between -0.50 and 0.50 are exactly 0.00.
It would of course be interesting to have the heuristic evaluation never return 0.00 (e.g. subtact 0.01 if it would be <= 0). Then you would know for sure that a 0.00 score in the root could only be caused by all relevant branches leading to a draw condition (3-fold-rep, 50-move, stalemate, insufficient material). It would mean that that player can force such a reglementary draw, and that it would judge itself to be at a disadvantage in any line that doesn't do that.
You don't have to be advanced very far to get that; you might be able to force a perpetual check.
It would of course be interesting to have the heuristic evaluation never return 0.00 (e.g. subtact 0.01 if it would be <= 0). Then you would know for sure that a 0.00 score in the root could only be caused by all relevant branches leading to a draw condition (3-fold-rep, 50-move, stalemate, insufficient material). It would mean that that player can force such a reglementary draw, and that it would judge itself to be at a disadvantage in any line that doesn't do that.
You don't have to be advanced very far to get that; you might be able to force a perpetual check.
-
- Posts: 11779
- Joined: Thu Mar 09, 2006 12:57 am
- Location: Birmingham UK
Re: Q: How to Detect a Draw?
Why are evals only calculated to 2 digits?
I'm not saying you'd get better move selection with more - but why go to the computational effort of truncating?
In order to truncate to 2 digits, one must use a "decimal" or "money" number format. Working with these formats is, computationally, MUCH more expensive (hence slower) that working with the float format - but if you don't use these formats, decimal numbers might not sum correctly - hence those of us who write business applications that sum numbers representing money don't think twice about using money formats - it's absolutely the right thing to do. However, in a chess engine that's generating game trees, CPU time is precious!
The simple reveals itself after the complex has been exhausted.
-
- Posts: 1847
- Joined: Tue Apr 19, 2016 6:08 am
- Location: U.S.A
- Full name: Andrew Grant
Re: Q: How to Detect a Draw?
Engines don't use floats for the evals. HGM is just expressing some conversation of engine eval into "human eval".
Friendly reminder that stealing is a crime, is wrong, and makes you a thief.
"Those who can't do, clone instead" - Eduard ( A real life friend, not this forum's Eduard )
"Those who can't do, clone instead" - Eduard ( A real life friend, not this forum's Eduard )
-
- Posts: 11779
- Joined: Thu Mar 09, 2006 12:57 am
- Location: Birmingham UK
Re: Q: How to Detect a Draw?
AndrewGrant wrote: ↑Sat Jun 29, 2024 11:01 amEngines don't use floats for the evals. HGM is just expressing some conversation of engine eval into "human eval".
Thank you Andrew - that's a good and clear answer.
The simple reveals itself after the complex has been exhausted.
-
- Posts: 2542
- Joined: Tue Aug 30, 2016 8:19 pm
- Full name: Rasmus Althoff
Re: Q: How to Detect a Draw?
Because both UCI and CECP transmit the score in centipawns. Even if an engine calculates e.g. in millipawns internally, or something entirely different such as winnning probability, it has to convert that to centipawns externally.
Rasmus Althoff
https://www.ct800.net
https://www.ct800.net
-
- Posts: 27965
- Joined: Fri Mar 10, 2006 10:06 am
- Location: Amsterdam
- Full name: H G Muller
Re: Q: How to Detect a Draw?
'Money format' is a concept of output formatting. Apart from that does not exist in most high-level computer languages used for programming engines, and is not supported by hardware. The only formats there are integer and floating point, and in the old days most CPUs did not support the latter (so the high-level languages emulated it with integer arithmetic). Floating-point formats tend to be large; the lowest precision x68 hardware supports is 4 bytes. So if you don't need that precision or wide value range, you can potentially save a factor 4 on table sizes. This can significantly reduce cache pressure on large tables, such as used to define neural nets.towforce wrote: ↑Sat Jun 29, 2024 10:57 amIn order to truncate to 2 digits, one must use a "decimal" or "money" number format. Working with these formats is, computationally, MUCH more expensive (hence slower) that working with the float format - but if you don't use these formats, decimal numbers might not sum correctly - hence those of us who write business applications that sum numbers representing money don't think twice about using money formats - it's absolutely the right thing to do. However, in a chess engine that's generating game trees, CPU time is precious!
So most engines only use integer arithmetic, often stored in byte-size variables. For things like piece-square tables that is good enough. The number 1 then represents the 'evaluation quantum'. It can be a centi-pawn, but doesn't need to be. E.g. in Joker I use 1/256 Pawn as quantum, and all evaluation weights are expressed as an integer multiple of this. That means you can use the fastest possible arithmetic on it, even on CPUs that do not support floating point at all. For relaying the score to the GUI the internal value is converted (and rounded) to an integer number of centi-pawn, as the communication protocol requires.
-
- Posts: 2839
- Joined: Wed Mar 10, 2010 10:18 pm
- Location: Hamburg, Germany
- Full name: Srdja Matovic
Re: Q: How to Detect a Draw?
Wish to add that the x87 FPU suported 32-bit, 64-bit and also 80-bit (think Fortran) floating-point format, with x86-64 SSE2 80-bit support (and x87 co-processor) was dropped, and meanwhile newer SIMD ISAs support also FP16 and BF16 format (Google's 16-bit floating-point format). As mentioned, this is of interest for neural networks, new GPUs increased throughput by FP8, FP6 and FP4 for LLMs, some papers mention that FP mixed precision is of interest for training NNs.hgm wrote: ↑Mon Jul 01, 2024 11:01 am [...]
Floating-point formats tend to be large; the lowest precision x68 hardware supports is 4 bytes. So if you don't need that precision or wide value range, you can potentially save a factor 4 on table sizes. This can significantly reduce cache pressure on large tables, such as used to define neural nets.
[...]
https://en.wikipedia.org/wiki/X87
https://en.wikipedia.org/wiki/SSE2#Diff ... U_and_SSE2
https://en.wikipedia.org/wiki/AVX-512#FP16
--
Srdja
-
- Posts: 5593
- Joined: Tue Feb 28, 2012 11:56 pm
Re: Q: How to Detect a Draw?
It would not mean that a draw can be forced by either side. One or both players could potentially reach a winning position that is statically evaluated as negative for that player.hgm wrote: ↑Sat Jun 29, 2024 10:39 am Well, for one the chances are not that small. Many of the games are not yet decided at that point, and 1% of the scores between -0.50 and 0.50 are exactly 0.00.
It would of course be interesting to have the heuristic evaluation never return 0.00 (e.g. subtact 0.01 if it would be <= 0). Then you would know for sure that a 0.00 score in the root could only be caused by all relevant branches leading to a draw condition (3-fold-rep, 50-move, stalemate, insufficient material). It would mean that that player can force such a reglementary draw, and that it would judge itself to be at a disadvantage in any line that doesn't do that.