lichess-bot-devs / lichess-bot

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

Let Homemade Engines Communicate via Chat #1007

Closed Others closed 6 days ago

Others commented 3 weeks ago

Unless I'm missing something, it's not currently possible to have a homemade engine read or write chat messages during games. (At least not without hacking around current abstractions.)

When developing my bot, it would be super helpful to be able to write a diagnostic message into chat in some exceptional situations. So I'm primarily interested in being able to type unilaterally during the "search" call.

I think I can probably accomplish what I want by just hacking on the code a little bit myself, but I'm wondering if it would be in scope for this to be properly supported by the project.

MarkZH commented 3 weeks ago

Communication by chat is very limited for all engine types (XBoard, UCI, and homemade) since lichess looks down on automated posting. The currently allowed messages are:

If you need diagnostic messages from your engine, is there a reason that the log files aren't sufficient?

Others commented 2 weeks ago

If you need diagnostic messages from your engine, is there a reason that the log files aren't sufficient?

It's just more inconvenient to cross reference logs rather than having it appear in the game log. Also my bot has some edge cases where it might play a bit odd (specific to my usecase) and I'd love to be able to tell the opponent something has gone a bit wrong.

lichess looks down on automated posting

Is this an official policy that you can cite from somewhere? I don't see documentation in the API reference.

I understand why this would apply to sending a ton of messages or posting in other people's games, but I'm not sure why having my bot post occasionally in the chat of its games would be an issue.

Responses to !commands

Would it be reasonable to let homemade engines add new commands? That would at least get me somewhat to where I want

p.s. I'm happy to contribute code for these suggested features, I just want to make sure you want the PR before I spend time on it :)

AttackingOrDefending commented 2 weeks ago

Communicating during the search isn't possible currently as lichess-bot is synchronous. So it would require quite a few changes to implement.

Also my bot has some edge cases where it might play a bit odd (specific to my usecase) and I'd love to be able to tell the opponent something has gone a bit wrong.

After, the search you can send a message to the user if it played a bit odd.

engine.play_move(board, game, li, setup_timer, move_overhead, can_ponder, is_correspondence, correspondence_move_time, engine_cfg, fake_think_time(config, board, game))
if engine.played_odd:  # Custom engine variable that gets set when playing an odd move.
    conversation.send_reply(ChatLine({"room": "player", "username": "", "text": ""}), "The engine played an odd move.")
time.sleep(to_seconds(delay))

The code isn't the cleanest but it may be good enough for your use case.

Is this an official policy that you can cite from somewhere? I don't see documentation in the API reference.

The code for the chat is here where you can also probobaly find the restrictions. In this issue the user mentions that when sending suplicate messages one should wait (the issue was from the point of the human player, but the same rules still apply).

Would it be reasonable to let homemade engines add new commands? That would at least get me somewhat to where I want p.s. I'm happy to contribute code for these suggested features, I just want to make sure you want the PR before I spend time on it :)

Some changes to make it simpler to add custom chat messages, like the one shown above, are good. I would accept a PR allowing engines to talk during games, provided it doesn't use some hacky methods (so probably no threading), but most desirable would be to allow this for all engine types (not only homemade) (e.g. see here the section about tellopponent MESSAGE, tellothers MESSAGE and tellall MESSAGE) (uci engines don't have that ability, adding a lichess-bot specific info string chat MESSAGE_HERE may be a bit to much).

MarkZH commented 2 weeks ago

The difficulty with using XBoard chat commands (tellopponent, etc.) is that python-chess doesn't support them. I just tried having my engine output tellall Good game! and python-chess printed the warning Unexpected engine output: 'tellall Good game!'. That library would have to be updated prior to this feature.

MarkZH commented 6 days ago

Since it seems like this feature would not be used by most players, I'm closing this issue. @Others, if you would like help while implementing this chat feature (@AttackingOrDefending's idea above seems a good way to go about it) feel free to reply here or start a discussion.