lichess-bot-devs / lichess-bot

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

EngineTerminatedError : Engine event loop dead #868

Closed Slivki-coder closed 10 months ago

Slivki-coder commented 10 months ago

I made my chess engine in python a few days ago and today I tried to put it on lichess. I converted it to an exe file using pyinstaller and then followed the instructions on this website. when I start up the engine in my cli it starts returning error like this:

 move: 1                                                                  lichess-bot.py:692
                    INFO     Searching for time 10 seconds for game RsahanPl                       engine_wrapper.py:621
                    INFO     Backing off play_game(...) for 29.4s (chess.engine.EngineTerminatedError:    _common.py:105
                             engine event loop dead)
[11/18/23 14:02:35] INFO     +++ https://lichess.org/RsahanPl/black Blitz vs Slivki1909 (993?)        lichess-bot.py:584
                             (RsahanPl)

The engine is online on lichess but it does not make moves until I log into the bot account and do the firstmove mannually. It plays normally after I do this and I think it is because lichess does not start the clocks until each player made a move. Do I need to change anything in the config.yml file? Here is my uci loop, if anyone could tell me where my mistake is I would be very grateful.

def uci_loop():
    while True:
        c = input()
        if c == "uci":
            print("id name bot_name")
            print("id author author_name")
            print("uciok")
        elif c == "isready":
            print("readyok")
        elif "position" in c:
            if not "moves" in c:
                pos = chess.Board()
            else:
                pos = chess.Board()
                cs = c.split("moves ")
                css = cs[1].split(" ")
                for move in css:
                    pos.push_san(move)
        elif "go" in c:
            cs = c.split(" ")
            wtime = int(cs[2])
            btime = int(cs[4])
            move = find_best_move(pos, wtime/30000 if pos.turn == chess.WHITE else btime/30000, True if pos.turn == chess.WHITE else False)
            print(f"bestmove {move}")
        elif c == "quit":
            break

The engine works fine in arena chess GUI

AttackingOrDefending commented 10 months ago

For the first move, your engine will receive a go movetime x command and not a go wtime x btime x winc x binc x. This command means that the engine mut search for exactly this amount of time. Your uci_loop() doesn't support such a command. First move engine communication:

2023-11-18 16:46:01,220 chess.engine (engine.py:1062) DEBUG <UciProtocol (pid=16956)>: << ucinewgame
2023-11-18 16:46:01,220 chess.engine (engine.py:1062) DEBUG <UciProtocol (pid=16956)>: << isready
2023-11-18 16:46:01,313 chess.engine (engine.py:1088) DEBUG <UciProtocol (pid=16956)>: >> readyok
2023-11-18 16:46:01,314 chess.engine (engine.py:1062) DEBUG <UciProtocol (pid=16956)>: << position startpos moves d2d4
2023-11-18 16:46:01,314 chess.engine (engine.py:1062) DEBUG <UciProtocol (pid=16956)>: << go movetime 10000
2023-11-18 16:46:01,315 chess.engine (engine.py:1088) DEBUG <UciProtocol (pid=16956)>: >> info string NNUE evaluation using nn-ea57bea57e32.nnue enabled
2023-11-18 16:46:01,316 chess.engine (engine.py:1088) DEBUG <UciProtocol (pid=16956)>: >> info depth 1 seldepth 1 multipv 1 score cp -34 nodes 20 nps 10000 hashfull 0 tbhits 0 time 2 pv d7d5
2023-11-18 16:46:01,317 chess.engine (engine.py:1088) DEBUG <UciProtocol (pid=16956)>: >> info depth 2 seldepth 2 multipv 1 score cp -34 nodes 40 nps 20000 hashfull 0 tbhits 0 time 2 pv d7d5

Later move engine communication:

2023-11-18 16:46:12,437 chess.engine (engine.py:1062) DEBUG <UciProtocol (pid=16956)>: << position startpos moves d2d4 d7d5 c2c4
2023-11-18 16:46:12,438 chess.engine (engine.py:1062) DEBUG <UciProtocol (pid=16956)>: << go wtime 180000 btime 177998 winc 0 binc 0
2023-11-18 16:46:12,448 chess.engine (engine.py:1088) DEBUG <UciProtocol (pid=16956)>: >> info string NNUE evaluation using nn-ea57bea57e32.nnue enabled
2023-11-18 16:46:12,449 chess.engine (engine.py:1088) DEBUG <UciProtocol (pid=16956)>: >> info depth 1 seldepth 1 multipv 1 score cp -6 nodes 35 nps 3888 hashfull 0 tbhits 0 time 9 pv d5c4
Slivki-coder commented 10 months ago

thanks that resolved the issue