Good day, i'm working on a project, a chess game with AI, and right now i'm at the stage of designing the function that checks if the king is in mate or checkmate. The only possible way i think about approaching this is by generating all the moves and see if any are in range to attack the king.
My question: Is there any less resource expensive way to do this ?
Generate your movelist ignoring check. Then, for each move you generated, check to see if the move leaves your
king in check. If it does, it is not a valid move; remove it from the list. If, after checking all moves, the movelist is
empty, you are checkmated. If the movelist contains at least one move, you are in check, and the movelist contains
only moves that get you out of check.