For the past couple of weeks, I've been making a chess engine, and right now I'm working on creating its search and evaluation phases.
To start off with, I made the evaluation phase a simple count of material so I could focus on the search phase, and then I would come back to create a more nuanced evaluation function. So right now, I have negamax, with alpha-beta pruning, iterative deepening, and quiescence searching implemented, which I'm pretty happy about.
But the problem is sometimes my engine still decides to willing blunder away pieces. Here's an example from a recent game, where the computer is black and it's black to move. For some reason, my engine decided that Ng4xf2 was the best move here. And then once it lost the knight for a pawn, it just went on as if it had made an equal trade.
Can this kind of blundering by a chess engine be explained away by a very naive evaluation phase, like my engine currently has? If it can be then, then of course the solution would be to create a much stronger evaluation function, which I'll do. But if it can't - and I must admit I don't see how it could - then I'm afraid there's a problem with the search phase, which would be a disappointing, but not impossible, setback.
I found this question, which seems to give an answer, but the reason why I still don't see how the evaluation function could be the culprit is that at the very least, in my mind, an evaluation phase based purely on material gain shouldn't make basic blunders where it loses material literally on the next move (especially with quiescence searching!)
Can anyone with experience in this area of AI programming offer any insight here? Also, let know if you need to see any code and I'll be more than happy to provide it.