lichess.org
Donate

Bug in python code.

I have written in a chess engine in python. I have implemented Negamax algorithm along with alpha-beta pruning and PSTS. I have added MVV-LVA move sorting and SEE. The bug is that it will miss mate-in-1s and instead it will play the move that achieves it the most score through PSTS and other evaluation functions. I tested the same position in a very basic minimax engine with no PSTS and nothing else except a very basic evaluation function that counts the material score and it was able to find the mate-in-1 and not only mate in 1 but it could find mate in 2 and 3 and so on until its the mate in _moves was less than the depth. My main chess engine which has the bug also has move ordering. To fix it I tried to make another function that will return 9999 score if the board was checkmate.( It will return the positive score only if the engine made the checkmate and if it got checkmated it will get the score -9999 and if the engine was playing black the score was just reversed.). That function still didn't help. If anyone knows how to solve it or anything please tell me and if you need the code message me.
Wow, if you just typed as if you were coding, no wonder why the thing doesnt work.

Ugly, disorganized, not a proper structure. Hard to spot a mistake because you want to look the way and not read due to how bad the thing looks. Disgusting.
@Alientcp Who asked? Just say you don't understand what I meant. It's clearly readable and now I get it that due to so much information it looks bad and unorganized but if you would tried to read rather than judge you would have understood. Skill Issue.
How did you fix it? Reading your question it seems unfixable, because how can any engine find mates deeper that the search depth?
@s2numbuq35i No the problem is moves that lead to checkmate, Just think theres a mate in 3 and the depth of the engine is 7. The issue is that the first move that continues the mate in 3 is getting prunned off due to soo many pruning methods and thus the engine misses the checkmate. Now it is very hard to pinpoint which exact method of pruning does that cause there are a ton of them. According to my observation, the engine doesnt calculate all the lines instead most lines are prunned very early, something around depth of 2. I did try to improve the logic which finally made the engine see checkmate(mostly mate in 1 and 2 regardless of the depth of the engine) and defend against checkmate. I did ask ChatGPT but it unable to give a logical answer and told me the purpose of the engine is to play the best move available in a position rather than actively seeking checkmate.
The reason which proved my observation true was the time difference in a basic brute force engine and my engine.
At 7 depth the minimax engine with alpha beta pruning took 2min and 32sec to find a move(No multiprocessing).
At same depth the engine with the issues took only 8secs(No multiprocessing). The funny thing is that this engine with issues performed way better than its previous versions on middle game positions( It performed with 1660 ELO and the previous version performed only at 1515 ELO).
How on earth someone supposed to help you without seeing your code???
@FreedBeast219 said in #8:
> @xDoubledragon I told in the beginning itself that message me for the code. Kindly read the entire thing before replying.
I don't think many people want to go through the effort of doing that. Not sure you wouldn't just share your code if you wanted help.

Anyways, congrats on resolving the issue.