lichess-bot-devs / lichess-bot

A bridge between Lichess bots and chess engines
GNU Affero General Public License v3.0
746 stars 440 forks source link

"go ponder" command for a checkmate position #702

Closed fabriciodosanjossilva closed 1 year ago

fabriciodosanjossilva commented 1 year ago

Consider this scenario: after a "go" command by lichess-bot, the engine returns "bestmove g2f3 ponder d1f3" and that these two consecutive moves lead to a chekmate (against the engine). The engine knows that the best move to play is g2f3 and it also knows that after that the opponent will immediately checkmate. It just hopes that the opponent does not play the winning d1f3 move. At this moment it is nonsense to ponder on the eventual d1f3 move because if it happens, it will be a checkmate position and therefore the game is already ended.

Currently, in this situation, lichess-bot issues a "go ponder" command, leading the engine to "think" on a dead position. Not many engines are ready for this and a crash is probably what we will see.

Who is to blame? Should it be lichess-bot by issuing a "go ponder" command on a checkmate position? Or shoud it be the engine, that mentioned "ponder d1f3" knowing that it is not ponderable?

fabriciodosanjossilva commented 1 year ago

I just tested that if the engine responds with a simple "bestmove g2f3", lichess-bot does not issue the "go ponder" command.

If this is the correct and expected behaviour, I'll close this issue.

MarkZH commented 1 year ago

Interesting question, although it may be better directed at the python-chess library. The call to self.engine.play() in EngineWrapper.search() results in both the go and go ponder commands if the ponder argument is true. Lichess-bot would have to detect mate-in-two board positions so that it could set ponder to false to prevent the go ponder command from being issued.

I think it's up to the engine not to issue a bestmove ... ponder ... response if the subsequent command to go ponder would result in a crash. Stockfish, at least, does nothing when commanded to ponder on a mating move and responds to stop with bestmove (none). I don't think crashing engines has been an issue. Most engines use the UCI protocol, so I would have expected to get bug reports about crashes in mating positions..

According to the UCI documentation (zip file with text document):

* go
  ...
    * ponder
        start searching in pondering mode.
        Do not exit the search in ponder mode, even if it's mate!

It would be an error to send an engine ponderhit in the event the ponder move is a checkmate or other game-ending move.

fabriciodosanjossilva commented 1 year ago

I'll consider that it's the engine responsability not to use "ponder x" in this case. I've patched my bot to meet this. I'll also patch my bot to deal with a "go" command on a mating position.

Thank you for all.

lichess-bot has no flaw in this topic. I'll close this issue.