How to find out that something is a Legal Move for my Chess Game?
Im currently Programming a Chess game. I want to mark all possible Moves for Piece if I click it. For a Move to be Legal it has to be following the Movement of the Piece, it has to be in Bounds of the Chessboard and it has to be safe for the own King. My Problem is with the last one. Because to determine if a Piece is attacking the King after a Move you would have to simulate it and than check if something can attack the King. but if just update all possible Moves and look if someting is attacking the King after the Simulation you get infinite Rekursion. My only way was to have an additonal variable (canAttackKing // after a move) and a Method just like the one to determine the possible Moves just without the Check if its safe. But this is just annoying and hard to take care of. Constantly there are some Bugs etc. So my Question is, is there a better way to determine if a Move is Safe?