Understanding the idea behind martingale betting setup to solve expected value problems Learning martingale theory I've come across a method that uses gambling strategies in martingale betting to calculate expectations. It's clever and I understand the solution but I'm not sure how they come up intuitively with the construction. I'd like to do so. Here are two examples:
Expected number of coin tosses to get a head: Find $\mathbb{E}[N]$ where $N$ is the number of coin tosses to get a head. Obviously this can be done via geometric dist but here's another way:

We gamble in such a way that we make money on heads but such that if we get a T on toss $n$, our position is $-n$.
We therefore gamble one unit on the first toss and on each toss after a $T$.
After one head, we gamble three. This guarantees that if we get a $T$ next then we go to $-n$.
After two heads we are therefore up 4, and so we gamble 7  to get us to $-n$ again. our gambling winnings is a martingale since we are making finite trades in a martingale (any bounded trading strategy in a martingale is a martingale).
After three heads our position is $11 - (n-3)=14-n$. the time taken to get three heads is a stopping time with finite expectation so if we stop at it we still have a martingale (Optional sampling theorem) thus $\mathbb E (14 -n) = 0 $ and we are done.

Expected number of coin tosses to get two consecutive heads with biased coin: Let $p$ indicate prob of head.

In order to keep martingale property we now say that we must win $(1-p)$ dollars when we throw a head and $p$ dollars otherwise. Clear enough so far. 
We now construct a strategy so that if we get a $T$ on toss $k$ then our position is $-kp$. We now have to find out how much to bet:
If we threw a tail on toss $k-2$ and a head on $k-1$, then if we gamble $y$ dollars on toss $k$ then our position will be:
$(1-p) - (k-2)p -yp$ and we would like this to be equal to $-kp$. This gives us that:
$y = \frac{1+p}{p}$
The value of our position at two successive heads would then be:
$-(k-2)p+ (1-p) + (1-p) \frac{1+p}{p}$ and since this again has exp $0$ via optional stopping this gives us $\mathbb{E}[k] = 2 + \frac{1-p}{p}(1 + \frac{1+p}{p})$.

I understand these solutions I think more or less, although right now they're not immediately intuitive to me.
What I really want to know is: given a general problem, how exactly are the betting strategies designed on these martingales tailored in order to get the solution we're looking for. Why $-n$ in the first problem but $-np$ in the second? Is it simply because the expected loss per unit is $-1$ and $-p$ respectively. So for any average problem with martingales will we be making a betting strategy that ensures that $T$ (or whatever equivalent) will have $-nq$ position at the $nth$ toss = $T$ where $-q$ is the unit payout?
 A: Perhaps the best way to really understand this method is to read the original paper that proposed it, [1].
A simple example is presented in [2]: Given a sequence of fair coin tosses, determine the expectation of the  waiting time $W$ for the pattern HTH.
In each step, a gambler enters, who bets a dollar on an initial H (receiving 2 back if correct), then if successful, 2 dollars on a T, and then (if successful again), 4 dollars on another H. All the bets are fair, so optional stopping implies that the expected net winnings of all the gamblers are zero. Every one of the $W$ relevant gamblers spent a dollar on the first bet,  one gambler received  2 back and another received 8 back.  Thus
$$0=E(8+2-W)=10-E(W).$$
Similarly, the expected waiting time for HHH is $8+4+2=14$.
[1] Li, Shuo-Yen Robert. "A martingale approach to the study of occurrence of sequence patterns in repeated experiments." the Annals of Probability 8, no. 6 (1980): 1171-1176.
https://projecteuclid.org/journals/annals-of-probability/volume-8/issue-6/A-Martingale-Approach-to-the-Study-of-Occurrence-of-Sequence/10.1214/aop/1176994578.short
[2]  https://www.yuval-peres-books.com/markov-chains-and-mixing-times/
Sec. 17.3.2 page 247
