PraxTube / chess-ai

A chess AI that uses alpha-beta to find the best move
MIT License
0 stars 1 forks source link

Engine: The number of moves doesn't match the expected number #17

Closed PraxTube closed 1 year ago

PraxTube commented 1 year ago

The current engine calculates the following amount of moves:

Depth 3: 9322

Depth 4: 206603

However the actual numbers are

Depth 3: 8902

Depth 4: 197281

See Shannon number

So the current engine somehow calculates too many moves. My suspicion is that moves like en passant aren't woring correctly or that moves regarding check are broken.

This might also be because of the 3 move repetition draw rule, which is not checked in the chess engine.

PraxTube commented 1 year ago

One possible way to deduce which illegal moves are causing the issue, we could generate ALL moves to say depth 3 by simply running each board with depth 1 and then add the total number of moves. If the number of moves equals the Shannon number in this case, then the illegal moves are likely caused by either repetition moves or on passant moves.

PraxTube commented 1 year ago

Note that depth=2 also gives wrong moves. We should see 400 moves, but we see 420.

PraxTube commented 1 year ago

Okay, so the problem seemed to be the following:

We counted every single node in the search tree, but the Shannon number only represents the nodes that get evaluated (i.e. the leaf nodes). You can also notice that we 420 instead of 400, in other words 420 - 20 = 400. Same with the others 9322 - 420 = 8902.

So this never really was a bug, but rather a misunderstanding.

It's also likely that the mentioned issue #23 is not related to this at all, though perhaps that too is a misunderstand of sorts?

PraxTube commented 1 year ago

See debug-node-moves branch for more info.