RSG-Group / Chess

Cool chess game
https://rsg-chess.now.sh/
Apache License 2.0
4 stars 0 forks source link

Sometimes AI doesn't make move. #10

Closed radi-cho closed 6 years ago

radi-cho commented 6 years ago

The problem: image

Check out this log to reproduce the problem: https://pastebin.com/VHgF51VW

UPDATE: How to reproduce:

radi-cho commented 6 years ago

Resolved. The problem is in the allMoves method, because it doesn't simulate for king checks.

The AI checks all moves and selects one of them. In the same time the black king is in check but the AI doesn't care, because allMoves calls piece.getValidMoves(/* undefined */). Then the AI tries to make that turn, but the checks in game.moveSelected don't allow this. The turn isn't made and that's it.

We can solve it by adding true as the simulate argument of getValidMoves.