lichess-bot-devs / lichess-bot

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

Won't play Atomic Game #973

Closed timmyFrederiksen closed 1 month ago

timmyFrederiksen commented 1 month ago

I'm making a bot that I want to only play atomic, and when I hooked up my logic for move finding with only normal chess enabled it runs fine (until it tries to play an illegal move because of differences with atomic), but when I switch the config.yml to only accept atomic, it won't even play the first move, even though the executable is the same in the engines folder.

When I run "python .\lichess-bot.py", it goes great until I challenge the bot to an atomic game, which is when I receive this error repeatedly:

2024-06-08 09:56:27,329 __mp_main__ (lichess-bot.py:780) INFO move: 1
2024-06-08 09:56:27,330 lib.engine_wrapper (engine_wrapper.py:705) INFO Searching for time 10 seconds for game 88n1VosB
2024-06-08 09:56:27,333 backoff (_common.py:105) INFO Backing off play_game(...) for 0.5s (chess.engine.EngineError: engine does not support UCI_Variant)

I'm sure, I'm misunderstanding something, the error message seems to imply that it's my engine, but I'm not exactly sure where it is going wrong, here is my engine's code and this exact engine runs on classic chess perfectly (again, until an illegal move is played, but the bot won't even play 1. Nf3 on atomic)

Here is the stack trace on the error in old.log:

2024-06-08 09:56:27,330 lib.engine_wrapper (engine_wrapper.py:705) INFO Searching for time 10 seconds for game 88n1VosB
2024-06-08 09:56:27,331 chess.engine (engine.py:1062) DEBUG <UciProtocol (pid=20156)>: << ucinewgame
2024-06-08 09:56:27,332 chess.engine (engine.py:1062) DEBUG <UciProtocol (pid=20156)>: << isready
2024-06-08 09:56:27,333 chess.engine (engine.py:1088) DEBUG <UciProtocol (pid=20156)>: >> readyok
2024-06-08 09:56:27,333 backoff (_common.py:105) INFO Backing off play_game(...) for 0.5s (chess.engine.EngineError: engine does not support UCI_Variant)
2024-06-08 09:56:27,333 lib.lichess (lichess.py:65) DEBUG Backing off 0.5 seconds after 1 tries calling function <function play_game at 0x0000029A21789900> with args () and kwargs {'li': <lib.lichess.Lichess object at 0x0000029A1DB45690>, 'control_queue': <AutoProxy[Queue] object, typeid 'Queue' at 0x29a217995a0>, 'user_profile': {'id': 'kaboombot', 'username': 'KaboomBot', 'perfs': {'bullet': {'games': 0, 'rating': 2000, 'rd': 500, 'prog': 0, 'prov': True}, 'blitz': {'games': 0, 'rating': 2000, 'rd': 500, 'prog': 0, 'prov': True}, 'rapid': {'games': 0, 'rating': 2000, 'rd': 500, 'prog': 0, 'prov': True}, 'classical': {'games': 0, 'rating': 2000, 'rd': 500, 'prog': 0, 'prov': True}, 'correspondence': {'games': 0, 'rating': 2000, 'rd': 500, 'prog': 0, 'prov': True}}, 'title': 'BOT', 'createdAt': 1717728795863, 'seenAt': 1717857526651, 'playTime': {'total': 2519, 'tv': 0}, 'url': 'https://lichess.org/@/KaboomBot', 'count': {'all': 25, 'rated': 0, 'ai': 0, 'draw': 2, 'drawH': 2, 'loss': 6, 'lossH': 6, 'win': 17, 'winH': 17, 'bookmark': 0, 'playing': 0, 'import': 0, 'me': 0}, 'followable': True, 'following': False, 'blocking': False, 'followsYou': False}, 'config': <lib.config.Configuration object at 0x0000029A21799570>, 'challenge_queue': <ListProxy object, typeid 'list' at 0x29a2179a8c0>, 'correspondence_queue': <AutoProxy[Queue] object, typeid 'Queue' at 0x29a217da710>, 'logging_queue': <AutoProxy[Queue] object, typeid 'Queue' at 0x29a217da9b0>, 'game_id': '88n1VosB'}
2024-06-08 09:56:27,336 chess.engine (engine.py:1059) DEBUG <UciProtocol (pid=20156)>: Process exited
2024-06-08 09:56:27,336 chess.engine (engine.py:1046) DEBUG <UciProtocol (pid=20156)>: Connection lost (exit code: 1, error: None)
2024-06-08 09:56:27,338 lib.lichess (lichess.py:67) DEBUG Exception: Traceback (most recent call last):
  File "C:\Users\16126\AppData\Local\Programs\Python\Python310\lib\site-packages\backoff\_sync.py", line 105, in retry
    ret = target(*args, **kwargs)
  File "C:\Users\16126\Desktop\Chess\lichess-bot\lichess-bot.py", line 669, in play_game
    engine.play_move(board,
  File "C:\Users\16126\Desktop\Chess\lichess-bot\lib\engine_wrapper.py", line 181, in play_move
    best_move = self.search(board, time_limit, can_ponder, draw_offered, best_move)
  File "C:\Users\16126\Desktop\Chess\lichess-bot\lib\engine_wrapper.py", line 257, in search
    result = self.engine.play(board,
  File "C:\Users\16126\AppData\Local\Programs\Python\Python310\lib\site-packages\chess\engine.py", line 2982, in play
    return future.result()
  File "C:\Users\16126\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 458, in result
    return self.__get_result()
  File "C:\Users\16126\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 403, in __get_result
    raise self._exception
  File "C:\Users\16126\AppData\Local\Programs\Python\Python310\lib\asyncio\tasks.py", line 445, in wait_for
    return fut.result()
  File "C:\Users\16126\AppData\Local\Programs\Python\Python310\lib\site-packages\chess\engine.py", line 1789, in play
    return await self.communicate(UciPlayCommand)
  File "C:\Users\16126\AppData\Local\Programs\Python\Python310\lib\site-packages\chess\engine.py", line 1133, in communicate
    return await command.result
  File "C:\Users\16126\AppData\Local\Programs\Python\Python310\lib\site-packages\chess\engine.py", line 1386, in _line_received
    self.line_received(engine, line)
  File "C:\Users\16126\AppData\Local\Programs\Python\Python310\lib\site-packages\chess\engine.py", line 1728, in line_received
    self._readyok(engine)
  File "C:\Users\16126\AppData\Local\Programs\Python\Python310\lib\site-packages\chess\engine.py", line 1734, in _readyok
    engine._position(board)
  File "C:\Users\16126\AppData\Local\Programs\Python\Python310\lib\site-packages\chess\engine.py", line 1607, in _position
    raise EngineError("engine does not support UCI_Variant")
chess.engine.EngineError: engine does not support UCI_Variant

and in new.log:

2024-06-08 10:16:54,530 urllib3.connectionpool (connectionpool.py:549) DEBUG https://lichess.org:443 "GET /api/bot/game/stream/ZEk7uYYh HTTP/1.1" 200 None
2024-06-08 10:16:54,531 __mp_main__ (lichess-bot.py:614) DEBUG Initial state: {'id': 'ZEk7uYYh', 'variant': {'key': 'atomic', 'name': 'Atomic', 'short': 'Atom'}, 'speed': 'rapid', 'perf': {'name': 'Atomic'}, 'rated': False, 'createdAt': 1717859810971, 'white': {'id': 'kaboombot', 'name': 'KaboomBot', 'title': 'BOT', 'rating': 1500, 'provisional': True}, 'black': {'id': 'tfrederiksen', 'name': 'tFrederiksen', 'title': None, 'rating': 1555}, 'initialFen': 'startpos', 'clock': {'initial': 600000, 'increment': 0}, 'type': 'gameFull', 'state': {'type': 'gameState', 'moves': '', 'wtime': 600000, 'btime': 600000, 'winc': 0, 'binc': 0, 'status': 'started'}}
2024-06-08 10:16:54,531 lib.engine_wrapper (engine_wrapper.py:65) DEBUG Starting engine: ['C:\\Users\\16126\\Desktop\\Chess\\lichess-bot\\engines\\bot.exe']
2024-06-08 10:16:54,533 asyncio (proactor_events.py:626) DEBUG Using proactor: IocpProactor
2024-06-08 10:16:54,554 chess.engine (engine.py:1040) DEBUG <UciProtocol (pid=25480)>: Connection made
2024-06-08 10:16:54,554 chess.engine (engine.py:1062) DEBUG <UciProtocol (pid=25480)>: << uci
2024-06-08 10:16:54,730 chess.engine (engine.py:1088) DEBUG <UciProtocol (pid=25480)>: >> Chess Random Mover
2024-06-08 10:16:54,730 chess.engine (engine.py:1088) DEBUG <UciProtocol (pid=25480)>: >> uciok
2024-06-08 10:16:54,731 __mp_main__ (lichess-bot.py:620) DEBUG The engine for game ZEk7uYYh has pid=25480
2024-06-08 10:16:54,731 __mp_main__ (lichess-bot.py:623) INFO +++ https://lichess.org/ZEk7uYYh/white Atomic vs tFrederiksen (1555) (ZEk7uYYh)
2024-06-08 10:16:54,731 __mp_main__ (lichess-bot.py:788) DEBUG Game state: {'type': 'gameState', 'moves': '', 'wtime': 600000, 'btime': 600000, 'winc': 0, 'binc': 0, 'status': 'started'}
2024-06-08 10:16:54,731 lib.conversation (conversation.py:102) INFO *** https://lichess.org/ZEk7uYYh/white [player] KaboomBot: Hi! I'm KaboomBot. Good luck!
2024-06-08 10:16:54,732 urllib3.connectionpool (connectionpool.py:1055) DEBUG Starting new HTTPS connection (3): lichess.org:443
2024-06-08 10:16:55,097 urllib3.connectionpool (connectionpool.py:549) DEBUG https://lichess.org:443 "POST /api/bot/game/ZEk7uYYh/chat HTTP/1.1" 200 11
2024-06-08 10:16:55,097 lib.conversation (conversation.py:102) INFO *** https://lichess.org/ZEk7uYYh/white [spectator] KaboomBot: Hi! I'm KaboomBot.
2024-06-08 10:16:55,222 urllib3.connectionpool (connectionpool.py:549) DEBUG https://lichess.org:443 "POST /api/bot/game/ZEk7uYYh/chat HTTP/1.1" 200 11
2024-06-08 10:16:55,223 __mp_main__ (lichess-bot.py:779) INFO 
2024-06-08 10:16:55,224 __mp_main__ (lichess-bot.py:780) INFO move: 1
2024-06-08 10:16:55,224 lib.engine_wrapper (engine_wrapper.py:705) INFO Searching for time 10 seconds for game ZEk7uYYh
2024-06-08 10:16:55,225 chess.engine (engine.py:1062) DEBUG <UciProtocol (pid=25480)>: << ucinewgame
2024-06-08 10:16:55,225 chess.engine (engine.py:1062) DEBUG <UciProtocol (pid=25480)>: << isready
2024-06-08 10:16:55,226 chess.engine (engine.py:1088) DEBUG <UciProtocol (pid=25480)>: >> readyok
2024-06-08 10:16:55,227 backoff (_common.py:105) INFO Backing off play_game(...) for 1.6s (chess.engine.EngineError: engine does not support UCI_Variant)
2024-06-08 10:16:55,227 lib.lichess (lichess.py:65) DEBUG Backing off 1.6 seconds after 2 tries calling function <function play_game at 0x0000025F2D979900> with args () and kwargs {'li': <lib.lichess.Lichess object at 0x0000025F29DC5690>, 'control_queue': <AutoProxy[Queue] object, typeid 'Queue' at 0x25f2d9895a0>, 'user_profile': {'id': 'kaboombot', 'username': 'KaboomBot', 'perfs': {'bullet': {'games': 0, 'rating': 2000, 'rd': 500, 'prog': 0, 'prov': True}, 'blitz': {'games': 0, 'rating': 2000, 'rd': 500, 'prog': 0, 'prov': True}, 'rapid': {'games': 0, 'rating': 2000, 'rd': 500, 'prog': 0, 'prov': True}, 'classical': {'games': 0, 'rating': 2000, 'rd': 500, 'prog': 0, 'prov': True}, 'correspondence': {'games': 0, 'rating': 2000, 'rd': 500, 'prog': 0, 'prov': True}}, 'title': 'BOT', 'createdAt': 1717728795863, 'seenAt': 1717858577974, 'playTime': {'total': 2519, 'tv': 0}, 'url': 'https://lichess.org/@/KaboomBot', 'count': {'all': 25, 'rated': 0, 'ai': 0, 'draw': 2, 'drawH': 2, 'loss': 6, 'lossH': 6, 'win': 17, 'winH': 17, 'bookmark': 0, 'playing': 0, 'import': 0, 'me': 0}, 'followable': True, 'following': False, 'blocking': False, 'followsYou': False}, 'config': <lib.config.Configuration object at 0x0000025F2D989570>, 'challenge_queue': <ListProxy object, typeid 'list' at 0x25f2d98a8c0>, 'correspondence_queue': <AutoProxy[Queue] object, typeid 'Queue' at 0x25f2d9ca710>, 'logging_queue': <AutoProxy[Queue] object, typeid 'Queue' at 0x25f2d9ca9b0>, 'game_id': 'ZEk7uYYh'}
2024-06-08 10:16:55,229 lib.lichess (lichess.py:67) DEBUG Exception: Traceback (most recent call last):
  File "C:\Users\16126\AppData\Local\Programs\Python\Python310\lib\site-packages\backoff\_sync.py", line 105, in retry
    ret = target(*args, **kwargs)
  File "C:\Users\16126\Desktop\Chess\lichess-bot\lichess-bot.py", line 669, in play_game
    engine.play_move(board,
  File "C:\Users\16126\Desktop\Chess\lichess-bot\lib\engine_wrapper.py", line 181, in play_move
    best_move = self.search(board, time_limit, can_ponder, draw_offered, best_move)
  File "C:\Users\16126\Desktop\Chess\lichess-bot\lib\engine_wrapper.py", line 257, in search
    result = self.engine.play(board,
  File "C:\Users\16126\AppData\Local\Programs\Python\Python310\lib\site-packages\chess\engine.py", line 2982, in play
    return future.result()
  File "C:\Users\16126\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 458, in result
    return self.__get_result()
  File "C:\Users\16126\AppData\Local\Programs\Python\Python310\lib\concurrent\futures\_base.py", line 403, in __get_result
    raise self._exception
  File "C:\Users\16126\AppData\Local\Programs\Python\Python310\lib\asyncio\tasks.py", line 445, in wait_for
    return fut.result()
  File "C:\Users\16126\AppData\Local\Programs\Python\Python310\lib\site-packages\chess\engine.py", line 1789, in play
    return await self.communicate(UciPlayCommand)
  File "C:\Users\16126\AppData\Local\Programs\Python\Python310\lib\site-packages\chess\engine.py", line 1133, in communicate
    return await command.result
  File "C:\Users\16126\AppData\Local\Programs\Python\Python310\lib\site-packages\chess\engine.py", line 1386, in _line_received
    self.line_received(engine, line)
  File "C:\Users\16126\AppData\Local\Programs\Python\Python310\lib\site-packages\chess\engine.py", line 1728, in line_received
    self._readyok(engine)
  File "C:\Users\16126\AppData\Local\Programs\Python\Python310\lib\site-packages\chess\engine.py", line 1734, in _readyok
    engine._position(board)
  File "C:\Users\16126\AppData\Local\Programs\Python\Python310\lib\site-packages\chess\engine.py", line 1607, in _position
    raise EngineError("engine does not support UCI_Variant")
chess.engine.EngineError: engine does not support UCI_Variant

If there's anything else needed, please let me know. I'm pretty sure this is not a bug, but I can't find anything in documentation or online that would explain the issue.

Thanks

timmyFrederiksen commented 1 month ago

I'm attaching text files with the code for both my config.yml (config.txt) and my engine (bot.txt) [coded in python]

bot.txt config.txt

AttackingOrDefending commented 1 month ago

In bot.txt can you try changing UCI_OK_COMMAND = 'uciok' to UCI_OK_COMMAND = 'option name UCI_Variant type combo default atomic var atomic\nuciok'?

timmyFrederiksen commented 1 month ago

Yes, that worked! Why did that work, haha?

MarkZH commented 1 month ago

In order to play chess variants, your bot needs to announce that it can play those variants. Otherwise, chess interfaces (like lichess-bot) will assume the bot only plays standard chess. That's the purpose of the option name UCI_Variant command. If your bot ever plays more variants, add more var parameters to the same line.

timmyFrederiksen commented 1 month ago

Appreciate the help!