lichess-bot-devs / lichess-bot

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

HTTP error: #736

Closed vibranium21 closed 1 year ago

vibranium21 commented 1 year ago

It seems that after making moves from chessdb, my bot seems to stop entering moves. Here are is the log, and my fork of AttackingOrDefending's lichess-bot: log.txt https://github.com/vibranium21/lichess-bot/tree/vibranium I also have print-debugged and found that my engine is giving legal UCI moves to the lichess-bot wrapper

MarkZH commented 1 year ago

When the chessdb lookup failed, the position r2qkbnr/pp1b1ppp/4p3/1BppN3/3P4/2P5/PP3PPP/RNBQK2R b KQkq - 0 7 was sent to your engine and the engine returned None. We can see this in the third to last line of the log:

2023-06-12 15:02:19,547 urllib3.connectionpool DEBUG https://lichess.org:443 "POST /api/bot/game/zTHQ6Lg5/move/None?offeringDraw=false HTTP/1.1" 400 29

Specifically,

POST /api/bot/game/zTHQ6Lg5/move/None?offeringDraw=false
                                 ^^^^

When you debug your engine, what does it return for the above FEN?


I looked at the code for Minimax_Get_Move(). I believe it's possible for the function call from Engine.search() to return None. I think this can happen due to mix-ups in whether the return evaluation should be negated (line 194 in movegeneration.py). The evaluate() function returns the score for white, but there is no check that the evaluation at a certain depth of search matches with the perspective of the score. The values of alpha and beta are swapped and negated for every recursive call, so these correspond to the current position's turn. The fact that the evaluation is negated when returning to a lower depth should mean that there is no need to check for if position.turn == chess.WHITE. Perhaps the return call of your evaluate() function should be something like: return eval if position.turn == chess.WHITE else -eval.

These are my guesses, I haven't tested them. I could be wrong.

vibranium21 commented 1 year ago

I made a simple uci testing board with python. It plays legal, and existing moves there. So I am confused with this. I am currently checking startegies.py as well, to see if there is a mistake there.

AttackingOrDefending commented 1 year ago

If you run the code below, your engine will return (None, -20000).

board = chess.Board("r2qkbnr/pp1b1ppp/4p3/1BppN3/3P4/2P5/PP3PPP/RNBQK2R b KQkq - 0 7")
print(Minimax_Get_Move(board, 4, board.turn, -20000, math.inf))
vibranium21 commented 1 year ago

I have tracked the issue down to my move ordering. If I am in fact wrong, I will notify, but I am pretty sure, as going back to my commits before move ordering, the bot works fine. Thank you!