-
-
Notifications
You must be signed in to change notification settings - Fork 531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Send game result to engines #998
Conversation
UCI engines receive the final board position. Xboard engines receive the final move of the game and a message describing the winner and reason for the game ending.
UCI engines do not expect to get a message once a game ends.
chess/engine.py
Outdated
""" | ||
Sends the engine the result of the game. | ||
|
||
UCI engines only recieve the final position of the board. XBoard engines |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhh ... this sounds like this method would send it, but if I understand correctly it doesn't.
@@ -2904,6 +2959,12 @@ def analysis(self, board: chess.Board, limit: Optional[Limit] = None, *, multipv | |||
future = asyncio.run_coroutine_threadsafe(coro, self.protocol.loop) | |||
return SimpleAnalysisResult(self, future.result()) | |||
|
|||
def send_game_result(self, board: chess.Board, winner: Optional[Color] = None, game_ending: Optional[str] = None, game_complete: bool = True) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make sure game_ending
cannot be used to inject arbitary commands (}\n...
).
Options are safe, but a similar thing slipped through wrt. Opponent
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would getting rid of the newlines and curly braces be sufficient?
game_ending = ' '.join(game_ending.split()).replace('{', '').replace('}', '')
Or, should an error be raised if the string contains new lines or curly braces?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with raising an exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make sure
game_ending
cannot be used to inject arbitary commands (}\n...
).Options are safe, but a similar thing slipped through wrt.
Opponent
.
Does send_opponent_information()
need fixing? The UCI version goes through configure()
, so that should be safe. What about the XBoard version?
On another note, the Github tests are failing because the link to stockfish no longer works. Stockfish 11 can only be downloaded from a dropbox folder, which I doubt would allow automated downloads for long. The new link to Stockfish 16 is: https://github.com/official-stockfish/Stockfish/releases/download/sf_16/stockfish-windows-x86-64-avx2.zip Github also has a cache mechanism to store files between test runs to negate the need to redownload or recreate them. We've done this in lichess-bot with this commit. |
Curly braces and newlines can allow arbitrary messages to be sent to an engine. Do not allow these characters to be sent in end-of-game messages. Add tests to make sure an exception is raised for invalid characters.
When a game is done, this method can be called to inform the engine of the final moves and the result of the game.
XBoard engines receive the final move of the game followed by a message like, for example,
result 1-0 {White mates}
. The second field is one of1-0
,0-1
,1/2-1/2
,*
to indicate white winning, black winning, draw, or an incomplete game. The message in curly braces is optional and meant for humans to read.If this method is called on a UCI engine, nothing happens, as those engines do not expect any endgame messages.