Reputation: 93
I have an algorithm as follows to prevent a player from choosing a move that puts it into check:
However, in step 2 (bolded), the program must check that whatever the other player does does not move the other player into check. This creates an infinite recursion that I'm not sure algorithmically how to avoid. What suggestions do people have for this situation?
Upvotes: 1
Views: 394
Reputation: 186
You can define another function which returns true
if the player's piece can move to the cell of the opponent's king and false
otherwise.
Now call this function for the opponent when you fake a move.
Upvotes: 2