lichess-org / api

Lichess API documentation and examples
https://lichess.org/api
GNU Affero General Public License v3.0
445 stars 148 forks source link

Incorrect status in gameState when game ends in threefold repetition #214

Closed MarkZH closed 1 year ago

MarkZH commented 2 years ago

In several recent bot games, the final gameState event had a 'status': 'started' even though the game had ended in a threefold repetition. The status of these messages should have been draw.

Lichess did detect the threefold repetition since a gameFinish was received for these games at the same time as the last gameState message.

Examples:


ID: S1B4n8zi (game link)

Final game stream message:

{'type': 'gameState',
 'moves': 'b1c3 d7d5 b2b3 d5d4 c3b1 e7e5 c1a3 g8f6 a3f8 h8f8 h2h3 c8f5 c2c3 c7c5 g2g4 f5e4 g1f3 f6d5 d2d3 e4f3 e2f3 d4c3 h3h4 b8c6 h4h5 d8a5 d1c1 c6d4 b3b4 a5b4 f3f4 c3c2 b1d2 d5f4 h1h3 f4h3 f1h3 b4c3 h5h6 d4f3 e1e2 f3d2 h6g7 f8g8 c1d2 c3a1 d2c2 a1h1 c2c5 h1h3 c5e5 e8d7 e5d5 d7e8 d5b5 e8e7 b5e5 e7d7 e5d5 d7e8 d5e4 e8d8 e4d5 d8e8',
 'wtime': 191330,
 'btime': 72430,
 'winc': 4000,
 'binc': 4000,
 'status': 'started'}

Final event stream message for this game:

{'type': 'gameFinish', 'game': {'fullId': 'S1B4n8ziaDc2', 'gameId': 'S1B4n8zi', 'fen': 'r3k1r1/pp3pPp/8/3Q4/6P1/3P3q/P3KP2/8 w - - 13 33', 'color': 'white', 'lastMove': 'd8e8', 'source': 'friend', 'variant': {'key': 'standard', 'name': 'Standard'}, 'speed': 'blitz', 'perf': 'blitz', 'rated': True, 'hasMoved': True, 'opponent': {'id': 'zeekat', 'username': 'BOT zeekat', 'rating': 1875}, 'isMyTurn': False, 'secondsLeft': 191, 'compat': {'bot': True, 'board': True}, 'id': 'S1B4n8zi'}}

ID: 3gkCLRwv (game link)

Final game stream message:

{'type': 'gameState',
 'moves': 'g2g3 g8f6 b2b3 b7b6 f1g2 b8c6 c1b2 d7d5 c2c4 e7e6 b1c3 h7h6 c4d5 e6d5 c3b5 f8c5 d2d4 c5b4 e1f1 c8f5 d1c1 d8d7 c1e3 e8d8 e3f4 g7g5 f4f3 d7e6 a2a3 b4d2 b3b4 f5c2 g3g4 c2e4 f3g3 d2f4 g3h3 f6g4 g2e4 e6e4 f2f3 g4e3 f1e1 e4g6 e1f2 g6f6 h3h5 e3c4 b2c1 c6d4 b5c3 d4e6 c1b2 c4b2 c3d5 f6d4 f2g2 d4d5 h5f7 d5e5 a1a2 b2d1 g1h3 d1c3 a2c2 c3d5 h3f4 d5f4 g2f2 f4h3 f2g2 h3f4 g2f2 f4h3 f2g2 h3f4',
 'wtime': 132990,
 'btime': 18220,
 'winc': 4000,
 'binc': 4000,
 'status': 'started'}

Final event stream for this game:

{'type': 'gameFinish', 'game': {'fullId': '3gkCLRwvEesC', 'gameId': '3gkCLRwv', 'fen': 'r2k3r/p1p2Q2/1p2n2p/4q1p1/1P3n2/P4P2/2R1P1KP/7R w - - 8 39', 'color': 'white', 'lastMove': 'h3f4', 'source': 'friend', 'variant': {'key': 'standard', 'name': 'Standard'}, 'speed': 'blitz', 'perf': 'blitz', 'rated': False, 'hasMoved': True, 'opponent': {'id': 'pigeonengine', 'username': 'BOT PigeonEngine', 'rating': 1826}, 'isMyTurn': False, 'secondsLeft': 133, 'compat': {'bot': True, 'board': True}, 'id': '3gkCLRwv'}}

In this final example, I modified my bot to keep playing after a threefold draw, and it encountered an error when it tried to send a move.

ID: 9yu2v4Zv (game link)

Final game stream message:

{'type': 'gameState',
 'moves': 'b2b3 e7e5 a2a4 b8c6 h2h4 g8f6 d2d3 d7d5 g2g3 c6b4 g1f3 e5e4 d3e4 f6e4 c2c3 d8f6 c1g5 e4c3 g5f6 c3d1 f6d4 c7c5 d4e5 f7f6 e1d1 f6e5 f3e5 c5c4 b3c4 f8d6 f2f4 d6e5 f4e5 d5c4 b1a3 c4c3 a1b1 b4a2 e2e4 c8g4 d1c2 g4f3 f1b5 e8e7 h1e1 a8d8 c2b3 d8d2 a3c4 d2d4 c4d6 d4d2 b1a1 d2b2 b3a3 a2b4 d6f5 e7f7 f5d4 f7e7 e1e3 f3e4 e3e4 g7g6 a1c1 b4a2 c1f1 h8f8 f1f8 e7f8 e4f4 f8e7 b5c4 a2b4 f4f7 e7d8 f7h7 a7a6 d4e6 d8e8 e6d4 e8d8 d4e6 d8e8 e6d4 e8d8',
 'wtime': 304010,
 'btime': 533450,
 'winc': 2000,
 'binc': 2000,
 'status': 'started'}

Final event stream message for this game:

{'type': 'gameFinish', 'game': {'fullId': '9yu2v4ZvkrrK', 'gameId': '9yu2v4Zv', 'fen': '3k4/1p5R/p5p1/4P3/PnBN3P/K1p3P1/1r6/8 w - - 8 44', 'color': 'white', 'lastMove': 'e8d8', 'source': 'friend', 'variant': {'key': 'standard', 'name': 'Standard'}, 'speed': 'rapid', 'perf': 'rapid', 'rated': True, 'hasMoved': True, 'opponent': {'id': 'littlegreenmanbot', 'username': 'BOT LittleGreenManBot', 'rating': 1688}, 'isMyTurn': False, 'secondsLeft': 304, 'compat': {'bot': True, 'board': True}, 'id': '9yu2v4Zv'}}

Attempt at sending move:

POST /api/bot/game/9yu2v4Zv/move/d4e6?offeringDraw=false HTTP/1.1

Response

400 Client Error: Bad Request for url: https://lichess.org/api/bot/game/9yu2v4Zv/move/d4e6?offeringDraw=false
kraktus commented 1 year ago

I cannot reproduce, when the game end with a 3fold the last two events I received were:

b'{"type":"gameState","moves":"e2e4 e7e5 g1f3 g8f6 f3g1 f6g8 g1f3 g8f6 f3g1 f6g8","wtime":896170,"btime":905480,"winc":3000,"binc":3000,"status":"started"}'

b'{"type":"gameState","moves":"e2e4 e7e5 g1f3 g8f6 f3g1 f6g8 g1f3 g8f6 f3g1 f6g8","wtime":896170,"btime":905480,"winc":3000,"binc":3000,"status":"draw"}'

With the final one correctly stating draw

MarkZH commented 1 year ago

I'm seeing the draw events in my logs, too. The second-to-last event has "status": "started", so my bot tries to make one more move, which results in the error due to sending a move to a non-existent game. That's not a big deal, though, since the game is over.