Answers.Body: <p>The short answer to your question is <strong>no</strong>, there is not a chess engine that can reliably show if one side has a forced draw.  For example, this locked position is quite clearly a draw to the human eye:</p>
  
  <p><img src="https://i.sstatic.net/7NLPu.png" alt="Locked position, hopeless draw"></p>
  
  <p>However, notice that the evaluation is <em>0.17</em>, not <em>0.00</em>.  Houdini also give <em>0.05</em> - ever so slightly good for white.  This is very important.  This suggests that the evaluation of <em>0.00</em> is reserved by these programs for a specific reason, and indeed it is.  Basically, even in an "equal" position, the computer will not ever say that the score is <em>0.00</em>, instead it will give a minute edge to one or the other side.  </p>
  
  <p>So with that background, on to the specifics!  First, if the game is just a draw due to the position (i.e. stalemate, insufficient material, etc.) most GUI's will pop up a message that says "Game Drawn", or something to that effect.  That leaves the more complicated cases that you mentioned in your question.  In order to cover most of those, I'll introduce another position.  This is taken from Morphy-NN 1-0, New Orleans Blindfold Simul:</p>
  
  <p><img src="https://i.sstatic.net/gzgco.png" alt="Morphy - NN 1-0, New Orleans Blindfold Simul"></p>
  
  <p>Notice that Morphy currently has mate in 6 starting with <code>18.b4+!</code>.  However, if Morphy somehow missed that this was mate, he still had a forced draw by repetition, which the computer quickly sees.  By increasing the number of variations that the computer displays, it is possible to see that after white plays a move like <code>18.Qxc3+?</code>, white can still force a draw, despite being down a rook and a piece.  The evaluation of <em>0.00</em> again tips us off that this is a special position in that the computer can calculate a perpetual check.  If the moves <code>18.Qxc3+? Kxd5</code> are made on the board, then the evaluation will be <em>0.00</em>, indicating that white's best continuation is to force a draw.  Failure to do this will lead to loss of the game with best play.  </p>
  
  <hr />
  
  <p>So to summarize, no existing engine can say with exact certainty that a position is a draw.  However, the evaluation of <em>0.00</em> is special, and if that shows up as either the main score, or the score for a variation, that means that a draw is probably being forced in that specific line.  The easiest way to check is playfully called "spacebar analysis" - when the user hits the spacebar over and over again to force the computer to play the top recommended move.  Eventually you will get to a position that is obvious to a human as well as the machine.  </p>
  
  <hr />
  
  <p>And finally, to address your point about "contempt"</p>
  
  <blockquote>
    <p>Another example is that if you need a win (i.e. a draw is just as bad
    as a loss) you might want to play a move with a slight negative
    evaluation to avoid giving your opponent the opportunity to force a
    draw. Even though this increases your chance of losing, it also
    increases your chance of winning.</p>
  </blockquote>
  
  <p>This is quite simply referred to as contempt among chess programmers.  Most engines will allow you to set the level of contempt in the settings.  A positive contempt setting (100 is usually a reasonable level for analysis) will tell the engine to try fairly hard (a pawn's worth) to avoid a draw.  A negative setting will cause the engine to seek a forced draw (i.e. insufficient material, stalemate, or perpetual).  </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-06-12T16:32:44.563Z
Answers.Text: This is roughly the same idea as in Wes Freeman's comment to the question, and just as what he describes requires some human input - "Forced draws show up in the listing pretty obviously [sometimes], but sometimes it's less clear" - your answer has the human contributing "spacebar analysis." This is why I suggest tweaking the evaluation function in my answer; we're making it so that the engine itself actually seeks out forced draws and lets us know when they are conclusively present. That seems to be the only substantive difference between the approaches.
Answers.UserDisplayName: ETD
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-06-12T16:37:00.283Z
Answers.Text: @EdDean I agree.  The hardest draws to find are the ones where an endgame can't be won, but one side can press for the win forever.  Separately, changing the engines' eval function would be one approach, but most likely not something that can be done in on a reasonable timescale.  It is possible to play around with contempt settings currently, but that does not do the same thing as re-programming an engine as you suggest either.  The human-editable settings are fairly limited on current engines.
Answers.UserDisplayName: Andrew
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-06-12T20:54:37.280Z
Answers.Text: That contempt setting is neat--hadn't noticed it.
Answers.UserDisplayName: Eve Freeman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-06-12T23:42:03.467Z
Answers.Text: By the way, I don't think 0.00 is always indicative of a forced draw, which you seemed to imply. I see it occasionally even early in openings--I suppose it just means that given the current position and material, it is likely even, and the evaluation happens to be 0.00.
Answers.UserDisplayName: Eve Freeman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-06-12T23:46:19.433Z
Answers.Text: @WesFreeman in Rybka *0.00* is reserved for a few special cases, most notably for forced draws.  I'm *not* sure if this is also true for other engines though.
Answers.UserDisplayName: Andrew
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-06-12T23:48:28.500Z
Answers.Text: Interesting. In stockfish it is definitely not. Just analyzing the opening position for a few seconds will return plenty of 0.00 scores.
Answers.UserDisplayName: Eve Freeman
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-13T18:25:12.273Z
Answers.Text: I would think a useful setting in some cases might be an option to search for situations where an officially recognizable draw-or-better condition could be reached within a specified number of moves, e.g. because the opponent will get another hour in the clock if the game were to last ten more moves, and one would have to abandon the game to leave for the airport if that were to occur (though "officially recognizable" might be slightly ambiguous, I would think that if within ten moves one reached a position where an opponent's moves were 100% forced, one could ask an arbiter...
Answers.UserDisplayName: supercat
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-13T18:26:44.403Z
Answers.Text: ...to assist the opponent in making the forced moves without undue delay, and an arbiter would instruct an opponent that any kind of persistent refusal to make the forced moves in a reasonable amount of time would be viewed as sufficiently unsportsmanlike conduct as to justify forfeiture.)
Answers.UserDisplayName: supercat
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-06-12T15:10:53.297Z
Answers.LastActivityDate: 2012-06-12T15:10:53.297Z
Answers.UserDisplayName: Andrew
Answers.Body: <p>Just as engines can, at certain points, see a forced mate some number of moves away, because there are forcing enough lines that the engine can see everything perfectly in the remaining depth until mate, there are also junctures in chess games that would allow an engine to see a forced draw for the same reason of being able to completely survey the limited possibilities in play.</p>
  
  <p>Moreover, it would be easy to tweak an engine's evaluation function in order to make it seek out and prefer moves that lead to such forced draws: just as achieving mate is typically given some enormous value that dwarfs all other numerical factors that the engine's evaluation algorithm considers in order to guide the engine's play toward the ultimate objective, one could instead give such an enormous numerical value to achieving one of the sorts of draws I have in mind.</p>
  
  <p>For instance, automatically evaluate any position in which the opponent has insufficient material to mate as +1000000. Then, if the engine ever finds itself with the option of forcing off that much material of the opponent's, it will let you know. Also, tweak the evaluation algorithm to evaluate any three-fold repetition as +1000000 instead of the usual 0. Then, if there is a forcible repetition (as in a perpetual check scenario), the engine will love it and let you know about it. Similarly, give +1000000 if one can forcibly reach a tablebase draw.</p>
  
  <p>You could also ensure that the engine will give these valuations only when there is complete certainty that the draws really are forcible (because the tree between here and there has been able to be fully checked), just as with an engine not announcing mate unless it is sure. Thus, you won't get any false positives, though there will of course be plenty of false negatives, which you sensibly/necessarily allow in your question.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-06-12T05:49:43.260Z
Answers.Text: I don't think that any engine will work like this "out of the box" due to contempt factors and the way that they prune.  Basically, if a draw was found, any line that won material would be excluded.  So for example checking the king would be preferable to capturing a free rook.  I'm considering posting a longer answer because there *are* ways to use current engines to do this, but I don't want to give away too many preparation secrets. ;)
Answers.UserDisplayName: Andrew
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-06-12T06:26:49.693Z
Answers.Text: No engine will work the way I described "out of the box," it's true, as they are designed to seek wins; for the same reason, you'd have to do some tweaking to make a normal engine play, say, suicide chess. I already have us modifying the evaluation function; any contempt factor can be tweaked/disabled along with what I suggested if need be, yes? My main point is that I think existing engines can be re-purposed (in a reasonably straightforward way) to function as Mark wants. So, at the moment at least, I still see this as a way to "use current engines." My mind can always be changed though. :)
Answers.UserDisplayName: ETD
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-06-12T05:30:34.287Z
Answers.LastActivityDate: 2012-06-12T05:42:09.780Z
Answers.LastEditDate: 2012-06-12T05:42:09.780Z
Answers.UserDisplayName: ETD
Body: <p>Is there any chess engine that has an analysis mode that can show if a position is a forced draw by either side?</p>
  
  <p>It is common for engines to output evaluations of 0.0 when they detect a draw. But an evaluation of 0.0 can mean many things. For example, assuming it is white to move, an evaluation of 0.0 can mean:</p>
  
  <ul>
  <li>The game is certainly a draw regardless of how either player plays (e.g. insufficient material).</li>
  <li>Both players can force a draw. Neither player can hope to win if their opponent plays perfectly.</li>
  <li>No matter which move white plays, the computer is 100% sure that black can force a draw if he wishes to. White cannot hope to win if black plays perfectly. A draw is the most likely outcome, but a deeper search might show that black can force a win.</li>
  <li>The computer is 100% sure that white can force a draw if he wishes to. Black cannot hope to win if white plays perfectly. A draw is the most likely outcome, but a  deeper search might show that white can force a win.</li>
  <li>The computer has not found a forced draw for either side, but the evaluation so far is exactly level. A draw is the most likely outcome, but a deeper search may later show an advantage for one side.</li>
  </ul>
  
  <p>Just to give an example of when this might be useful, if white doesn't need to win and just wants to be as sure as possible of getting a draw then they might prefer to play a move with evaluation +0.0 and a known forced draw even though another move with a higher evaluation is available.</p>
  
  <p>Another example is that if you <em>need</em> a win (i.e. a draw is just as bad as a loss) you might want to play a move with a slight negative evaluation to avoid giving your opponent the opportunity to force a draw. Even though this increases your chance of losing, it also increases your chance of winning.</p>
  
  <p>Obviously there are positions where it is difficult or impossible to be sure whether a forced draw is available or not. But if the engine announces a forced draw then it <em>must</em> be possible to force a draw. False negatives are acceptable but there should be no false positives.</p>
  
  <p>So in summary, I'd like to know for a specific position if one (or both players) have a forced draw available to them. Calculating the numerical evaluation of the position is not necessary, but if it also provides this at the same time, that's a bonus.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2012-06-03T00:55:54.107Z
Comments.Text: Isn't knowing this part of the point of the 6-piece endgame tables?
Comments.UserDisplayName: Tony Ennis
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2012-06-03T16:37:50.663Z
Comments.Text: Table bases help, because then you know that a score of 0.0 is for certain a forced draw with optimal play. But I'd like the engine to tell me if it finds a forced draw from any arbitrary starting position, including (especially) when there are more than 6 pieces. For example, if white gets into a position where they can force perpetual check I'd like the engine to tell me that, even if it's not necessarily white's best move according to the evaluation function.
Comments.UserDisplayName: Mark Byers
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2012-06-04T15:08:15.700Z
Comments.Text: I am curious when you'd actually be able to take advantage of this sort of calculation in practice. This would be a nice feature. In stockfish I use the UCI analysis "multiple variation" feature, which sorts the moves in order of their evaluation score. Forced draws show up in the listing pretty obviously when they're perpetual checks or stalemates, but sometimes it's less clear, and as you say, if you go deeper it might not be a draw.
Comments.UserDisplayName: Eve Freeman
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2013-03-26T14:30:13.087Z
Comments.Text: But how forced is forced? I think that in many cases of so-called forced draws, the opponent can still deviate but at the cost of a clearly worse position. A position in which white can force either a draw or a full rook up wouldn't be a forced draw, limiting the usefulness.
Comments.UserDisplayName: RemcoGerlich
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2013-03-26T14:33:26.423Z
Comments.Text: If white can force a draw instead of going a rook up then I would like to know that.
Comments.UserDisplayName: Mark Byers
Tags: <analysis><engines><draw>
Title: Is there any chess engine that can show if one side has a forced draw?
ThreadText: # Is there any chess engine that can show if one side has a forced draw?
  
  (Asked by: username_0 on 2012-06-02)
  
  Is there any chess engine that has an analysis mode that can show if a position is a forced draw by either side?
  
  It is common for engines to output evaluations of 0.0 when they detect a draw. But an evaluation of 0.0 can mean many things. For example, assuming it is white to move, an evaluation of 0.0 can mean:
  
  * The game is certainly a draw regardless of how either player plays (e.g. insufficient material).
  * Both players can force a draw. Neither player can hope to win if their opponent plays perfectly.
  * No matter which move white plays, the computer is 100% sure that black can force a draw if he wishes to. White cannot hope to win if black plays perfectly. A draw is the most likely outcome, but a deeper search might show that black can force a win.
  * The computer is 100% sure that white can force a draw if he wishes to. Black cannot hope to win if white plays perfectly. A draw is the most likely outcome, but a deeper search might show that white can force a win.
  * The computer has not found a forced draw for either side, but the evaluation so far is exactly level. A draw is the most likely outcome, but a deeper search may later show an advantage for one side.
  
  Just to give an example of when this might be useful, if white doesn't need to win and just wants to be as sure as possible of getting a draw then they might prefer to play a move with evaluation +0.0 and a known forced draw even though another move with a higher evaluation is available.
  
  Another example is that if you *need* a win (i.e. a draw is just as bad as a loss) you might want to play a move with a slight negative evaluation to avoid giving your opponent the opportunity to force a draw. Even though this increases your chance of losing, it also increases your chance of winning.
  
  Obviously there are positions where it is difficult or impossible to be sure whether a forced draw is available or not. But if the engine announces a forced draw then it *must* be possible to force a draw. False negatives are acceptable but there should be no false positives.
  
  So in summary, I'd like to know for a specific position if one (or both players) have a forced draw available to them. Calculating the numerical evaluation of the position is not necessary, but if it also provides this at the same time, that's a bonus.
  
  **Tags:** analysis, engines, draw
  
  > **Comments:**
  > **username_1**: Isn't knowing this part of the point of the 6-piece endgame tables?  
  > **username_0**: Table bases help, because then you know that a score of 0.0 is for certain a forced draw with optimal play. But I'd like the engine to tell me if it finds a forced draw from any arbitrary starting position, including (especially) when there are more than 6 pieces. For example, if white gets into a position where they can force perpetual check I'd like the engine to tell me that, even if it's not necessarily white's best move according to the evaluation function.  
  > **username_2**: I am curious when you'd actually be able to take advantage of this sort of calculation in practice. This would be a nice feature. In stockfish I use the UCI analysis "multiple variation" feature, which sorts the moves in order of their evaluation score. Forced draws show up in the listing pretty obviously when they're perpetual checks or stalemates, but sometimes it's less clear, and as you say, if you go deeper it might not be a draw.  
  > **username_3**: But how forced is forced? I think that in many cases of so-called forced draws, the opponent can still deviate but at the cost of a clearly worse position. A position in which white can force either a draw or a full rook up wouldn't be a forced draw, limiting the usefulness.  
  > **username_0**: If white can force a draw instead of going a rook up then I would like to know that.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_4 on 2012-06-12. Score: 11
  
  The short answer to your question is **no**, there is not a chess engine that can reliably show if one side has a forced draw. For example, this locked position is quite clearly a draw to the human eye:
  
  ![Locked position, hopeless draw](https://i.sstatic.net/7NLPu.png)
  
  However, notice that the evaluation is *0.17*, not *0.00*. Houdini also give *0.05* - ever so slightly good for white. This is very important. This suggests that the evaluation of *0.00* is reserved by these programs for a specific reason, and indeed it is. Basically, even in an "equal" position, the computer will not ever say that the score is *0.00*, instead it will give a minute edge to one or the other side.
  
  So with that background, on to the specifics! First, if the game is just a draw due to the position (i.e. stalemate, insufficient material, etc.) most GUI's will pop up a message that says "Game Drawn", or something to that effect. That leaves the more complicated cases that you mentioned in your question. In order to cover most of those, I'll introduce another position. This is taken from Morphy-NN 1-0, New Orleans Blindfold Simul:
  
  ![Morphy - NN 1-0, New Orleans Blindfold Simul](https://i.sstatic.net/gzgco.png)
  
  Notice that Morphy currently has mate in 6 starting with `18.b4+!`. However, if Morphy somehow missed that this was mate, he still had a forced draw by repetition, which the computer quickly sees. By increasing the number of variations that the computer displays, it is possible to see that after white plays a move like `18.Qxc3+?`, white can still force a draw, despite being down a rook and a piece. The evaluation of *0.00* again tips us off that this is a special position in that the computer can calculate a perpetual check. If the moves `18.Qxc3+? Kxd5` are made on the board, then the evaluation will be *0.00*, indicating that white's best continuation is to force a draw. Failure to do this will lead to loss of the game with best play.
  
  ---
  
  So to summarize, no existing engine can say with exact certainty that a position is a draw. However, the evaluation of *0.00* is special, and if that shows up as either the main score, or the score for a variation, that means that a draw is probably being forced in that specific line. The easiest way to check is playfully called "spacebar analysis" - when the user hits the spacebar over and over again to force the computer to play the top recommended move. Eventually you will get to a position that is obvious to a human as well as the machine.
  
  ---
  
  And finally, to address your point about "contempt"
  
  > Another example is that if you need a win (i.e. a draw is just as bad
  > as a loss) you might want to play a move with a slight negative
  > evaluation to avoid giving your opponent the opportunity to force a
  > draw. Even though this increases your chance of losing, it also
  > increases your chance of winning.
  
  This is quite simply referred to as contempt among chess programmers. Most engines will allow you to set the level of contempt in the settings. A positive contempt setting (100 is usually a reasonable level for analysis) will tell the engine to try fairly hard (a pawn's worth) to avoid a draw. A negative setting will cause the engine to seek a forced draw (i.e. insufficient material, stalemate, or perpetual).
  
  > **Comments:**
  > **username_5**: This is roughly the same idea as in Wes Freeman's comment to the question, and just as what he describes requires some human input - "Forced draws show up in the listing pretty obviously [sometimes], but sometimes it's less clear" - your answer has the human contributing "spacebar analysis." This is why I suggest tweaking the evaluation function in my answer; we're making it so that the engine itself actually seeks out forced draws and lets us know when they are conclusively present. That seems to be the only substantive difference between the approaches.  
  > **username_4**: @EdDean I agree.  The hardest draws to find are the ones where an endgame can't be won, but one side can press for the win forever.  Separately, changing the engines' eval function would be one approach, but most likely not something that can be done in on a reasonable timescale.  It is possible to play around with contempt settings currently, but that does not do the same thing as re-programming an engine as you suggest either.  The human-editable settings are fairly limited on current engines.  
  > **username_2**: That contempt setting is neat--hadn't noticed it.  
  > **username_2**: By the way, I don't think 0.00 is always indicative of a forced draw, which you seemed to imply. I see it occasionally even early in openings--I suppose it just means that given the current position and material, it is likely even, and the evaluation happens to be 0.00.  
  > **username_4**: @WesFreeman in Rybka *0.00* is reserved for a few special cases, most notably for forced draws.  I'm *not* sure if this is also true for other engines though.  
  > **username_2**: Interesting. In stockfish it is definitely not. Just analyzing the opening position for a few seconds will return plenty of 0.00 scores.  
  > **username_6**: I would think a useful setting in some cases might be an option to search for situations where an officially recognizable draw-or-better condition could be reached within a specified number of moves, e.g. because the opponent will get another hour in the clock if the game were to last ten more moves, and one would have to abandon the game to leave for the airport if that were to occur (though "officially recognizable" might be slightly ambiguous, I would think that if within ten moves one reached a position where an opponent's moves were 100% forced, one could ask an arbiter...  
  > **username_6**: ...to assist the opponent in making the forced moves without undue delay, and an arbiter would instruct an opponent that any kind of persistent refusal to make the forced moves in a reasonable amount of time would be viewed as sufficiently unsportsmanlike conduct as to justify forfeiture.)  
  
  ---
  
  ### Answer by username_5 on 2012-06-12. Score: 4
  
  Just as engines can, at certain points, see a forced mate some number of moves away, because there are forcing enough lines that the engine can see everything perfectly in the remaining depth until mate, there are also junctures in chess games that would allow an engine to see a forced draw for the same reason of being able to completely survey the limited possibilities in play.
  
  Moreover, it would be easy to tweak an engine's evaluation function in order to make it seek out and prefer moves that lead to such forced draws: just as achieving mate is typically given some enormous value that dwarfs all other numerical factors that the engine's evaluation algorithm considers in order to guide the engine's play toward the ultimate objective, one could instead give such an enormous numerical value to achieving one of the sorts of draws I have in mind.
  
  For instance, automatically evaluate any position in which the opponent has insufficient material to mate as +1000000. Then, if the engine ever finds itself with the option of forcing off that much material of the opponent's, it will let you know. Also, tweak the evaluation algorithm to evaluate any three-fold repetition as +1000000 instead of the usual 0. Then, if there is a forcible repetition (as in a perpetual check scenario), the engine will love it and let you know about it. Similarly, give +1000000 if one can forcibly reach a tablebase draw.
  
  You could also ensure that the engine will give these valuations only when there is complete certainty that the draws really are forcible (because the tree between here and there has been able to be fully checked), just as with an engine not announcing mate unless it is sure. Thus, you won't get any false positives, though there will of course be plenty of false negatives, which you sensibly/necessarily allow in your question.
  
  > **Comments:**
  > **username_4**: I don't think that any engine will work like this "out of the box" due to contempt factors and the way that they prune.  Basically, if a draw was found, any line that won material would be excluded.  So for example checking the king would be preferable to capturing a free rook.  I'm considering posting a longer answer because there *are* ways to use current engines to do this, but I don't want to give away too many preparation secrets. ;)  
  > **username_5**: No engine will work the way I described "out of the box," it's true, as they are designed to seek wins; for the same reason, you'd have to do some tweaking to make a normal engine play, say, suicide chess. I already have us modifying the evaluation function; any contempt factor can be tweaked/disabled along with what I suggested if need be, yes? My main point is that I think existing engines can be re-purposed (in a reasonably straightforward way) to function as Mark wants. So, at the moment at least, I still see this as a way to "use current engines." My mind can always be changed though. :)  
  
  ---
  
  