This article might help you: http://www.nkc.u-tokyo.ac.jp/study_info/study_info01_04_j.html
I believe は has a grammatical role, as it can make a subject or an object, you know.
Somewhere I read that I should simply look at what is marked by は as if it were connected to the main verb (so the last verb in the sentence).
I think this is almost correct, because a topic is what you really want to focus in a sentence and it is often said by the main verb of a whole sentence.
So when you find は at the beginning of a long sentence, mark it as the topic. Its grammatical role (subject/object) is determined by checking the rest of the sentence. Examples:
日本は去年結婚した私の息子が住んでいる国だ。
Japan is the country where my son who married last year is living.
In the above sentence, the topic is Japan. So the speaker's intent is to tell listeners additional information about Japan rather than information about his son.
Grammatically, the rest of the sentence [去年結婚した私の息子が住んでいる国だ] is a verb phrase ([去年結婚した私の息子が住んでいる] modifies [国だ]) and it does not require an object, so Japan becomes a subject.
数学は山田先生が教えている。
Mr. Yamada teaches mathematics.
In this example, the topic is mathematics. So the interest of listeners is who teaches mathematics, not what Mr. Yamada does.
Grammatically this は makes an object since the verb phrase [山田先生が教えている] needs an object.
Note that the case exists that は is neither a subject nor an object:
象は鼻が長い。
Elephants have a long trunk.
In the above sentence, the verb is [長い]. It doesn't take an object, so [象は] is not an object. [象は] is neither a subject because if [象は] was a subject, the meaning would be like "Elephants are long."
There is a discussion among Japanese about this kind of sentences. 三上章 (Mikami Akira) persists that it has no subject.
Next, if you find find は at the middle of sentence, it can usually be moved to the top of sentence without changing its meaning unless it is contained in a relative clause. So you shouldn't be so scared; it is just indicating a topic too.
目まぐるしい人工知能の進歩により将棋は人間の手が届かないものになってしまった。
The rapid advancement of artificial intelligence has made Shogi what the human cannot reach.
The topic of this sentence is Shogi, which is a subject here. Its meaning the same as [将棋は目まぐるしい人工知能の進歩により人間の手が届かないものになってしまった。], tough the former is a bit more natural to me.
Hope my answer is your help.
Edit (in response to the first comment)
what if I find first a には、では、とは or even にとっては、に対しては、によっては、 and after that a normal は?
You know, は has major two meanings: one is a topic maker we are discussing here, and the other is a contrastive particle.
If you find two は-s in one sentence, it is unlikely that more than one は-s are topic makers. This is because it is quite unnatural that a sentence has more than one topics.
実際には質問の文はなくてもかまいません
Actually, the sentence in question can be omitted.
In this sentence, the first は in には is for contrast; the writer says that "Actually the sentence can be omitted though it isn't here." the second は is a topic maker.
I think particle+は is very much likely to be contrast rather than a topic. I couldn't find any example in which particle+は is a topic maker.
So it is usually OK to take such words as contrastive ones.
The same applies to words like に対しては, によっては and others:
やり方によっては彼は勝てるかもしれない。
He might have a chance to win in some way. (by some particular method, not by the others)
Contrastive は is sometimes close to emphasis. In such cases は restricts the meaning of sentence into a particular region as in the sentence below:
その子は勉強が得意だが、数学者としては未熟だ。
The boy is good at studying, but he is still inexperienced as a mathematician.
In this sentence, は emphasizes the phrase [数学者として] by separating mathematicians and all the others. So the sentence implies that the speaker does not do any evaluation on the boy out of the domain of mathematicians.