I am working on a variation of the classical gambler's ruin. Assume the gambler has $\$100$ and can bet on something. For example, the probability of winning is $40\%$ (i.e., if he bets $B$ dollars, he wins $B$ dollars with $40\%$ probability and loses $B$ dollars with $60\%$ probability). However, unlike in the classical gambler's ruin, he must bet all of his current money for each bet but never more than necessary. His final fortune can only be $\$0$ or $\$500$.
For example, if he has $\$200$, he will bet all the money. However, if he has $\$400$, he will only bet $\$100$ because if he wins this bet, the goal is achieved. And even if he loses, he has some chances to bet. The idea is that if the gambler has little money, he tends to be a risk seeker. Therefore, he wants to bet all the money to earn high returns. However, if he is close to the goal, he tends to be more conservative.
So, if at some stage $t$ of the game he owns $0 < X_t \leq 250$, he will bet $X_t$. If he owns $250 < X_t < 500$, he will bet $500−X_t$. If $X_t=0$, the game ends with a loss. If $X_t=500$, the game ends with a win. He starts out with $X_0=100$.
What is the probability that his final wealth reaches $\$500$ before losing all his money?
Could someone please provide some ideas to solve this question?

All you have to figure out is the tree of possible developments of the game:
Let's say the probability of winning in one round is $p$, then the probability of having won after maximum 4 rounds is $$p^3 + p^3(1-p) \; .$$ The probability of having lost after max 4 rounds is $$(1-p)+p(1-p) \; .$$ And the probability of the game not being decided yet after max 4 rounds is $$p^2(1-p)^2 \; .$$
Which means in the long run, the probability of winning is
$$\frac{p^3+p^3(1-p)}{1 - p^2(1-p)^2} \; .$$