Prbability of success in gambler's ruin
Let the probability of success be $h_x = \prob(X_T=a)$.
For $x=1,2,\ldots,a-1$, using the law of total probability $$ \begin{align*} h_x &= \prob(Y_1=1)\prob(X_T=a|Y_1=1)+\prob(Y_1=-1)\prob(X_T=a|Y_1=-1) \\ &= ph_{x+1} + qh_{x-1} \end{align*} $$ and boundary condition is $$ h_0 = 0, \quad h_a=1. $$ Solving (derivation), $$ h_x = \begin{cases} \dfrac ax, &p=\dfrac12, \\ \dfrac{1-(p/q)^x}{1-(p/q)^a}, &p\neq\dfrac12. \end{cases} $$