SebLague / Chess-Challenge

Create your own tiny chess bot!
https://www.youtube.com/watch?v=Ne40a5LkK6A
MIT License
1.78k stars 1.07k forks source link

There should be a quick way to check for only legal moves with checks and captures. #468

Open mrgwbland opened 10 months ago

mrgwbland commented 10 months ago

You can get just the legal moves which are captures so why not for checks as well? It would be a lot better than having to do the following code: Move[] legalMoves = board.GetLegalMoves(); foreach (Move move in legalMoves) { board.MakeMove(move); if (move.IsCapture||board.IsInCheck()) { code } else board.UndoMove(move); }

Edward-789 commented 10 months ago

The API cannot check if the board is in check without actually playing the move and then checking if the board is in check.

jongdetim commented 10 months ago

Edward is correct, and it's probably not getting changed, so you'll have to just spend the tokens if you want a list of checking moves