Modified gambler's ruin problem: quit when going bankruptcy or losing $k$ dollars in all

In each round, the gambler either wins and earns 1 dollar, or loses 1 dollar. The winning probability in each round is $p<1/2$. The gambler initially has $a$ dollars. He quits the game when he has no money, or he has lost $k>a$ rounds in all by this time, no matter how many rounds he wins. (For example, if $a=2$, $k=3$, and the sequence is +1,+1,+1,-1,+1,-1,-1, he quits now.) What is his expected exit time?

What confuses me is the dependence between these two events. I know the generating function of the exit time in the standard gambler’s ruin problem, and the duration until the gambler loses $k$ dollars in all is a negative binomial random variable. But these two stopping times are dependent. I was wondering if anyone could give me some hint. Thanks a lot!

Update: From Ross Millikan’s hint: how to calculate the probability that the wealth is $b$ at the end of round $2k-a$, given that the game is not over?

Solutions Collecting From Web of "Modified gambler's ruin problem: quit when going bankruptcy or losing $k$ dollars in all"

For the loss of $k$ to kick in, he needs to win $k-a$ times. If he does that, he will never go broke (except maybe on the round he would quit because of the $k$ losses). He needs to win those $k-a$ within the first $2k-a$ games. So compute the chance he goes broke in less than $2k-a$ games and the expected length of a game in that scenario. This gives you the chance he invokes the $k$ losses. Now compute the expected length of a game given that he wins at least $k-a$ in the first $2k-a$