Added logic to check for checkmate/stalemate before each move