Let's consider a one-dimensional Random Walk. At each time the walker moves of one step to the right with probability $p$ and to the left with probability $q$, with $p+q=1$. The walk is not symmetric, then $p \neq q$
How can I find the explicit formula of the probability to hit for the first time one of the two walls located in $x=n$ and $x=-n$ at time $t$, given that the walk started from $x=0$ at time $t=0$?
In order for the walker to reach position $x$ at time $t$. A necessary condition is $x \equiv t \pmod 2$. Assume this is true, the walker have make $s = \frac{t+x}{2}$ steps forward and $t - s = \frac{t-x}{2}$ steps backward.
In the absence of walls, the probablity for the walker to be at position $x$ is given by
$$P_{free}(x,t) = \operatorname{Prob}\left[\,X(t) = x\,\right] =\binom{t}{\frac{t+x}{2}} p^{\frac{t+x}{2}} q^{\frac{t-x}{2}} $$
In the presence of walls, the probability for the walker at position $x$ and never hit the walls before will be modified to: $$\begin{align} P(x,t) &= \operatorname{Prob}\left[\,X(t) = x : -n < X(t') < n,\,\forall t' < t\,\right] \\&=\sum_{r = \lceil\frac{x-t}{2n}\rceil}^{\lfloor\frac{x+t}{2n}\rfloor} (-1)^{r} \binom{t}{\frac{t+x-2rn}{2}} p^{\frac{t+x}{2}} q^{\frac{t-x}{2}} \end{align}$$
The formula can be derived using reflection principle. It is equivalent to start the random walk at time $t = 0$ with $(-1)^r$ phantom walker at position $\pm 2rn$ for each $r \in \mathbb{N}$. The range of summation over $r$ in above formula is limited to those which will actually contribute to $P(x,t)$ at time $t$.
For the walker to hit the wall $\pm n$ at time $t$, we again require $t \equiv n \pmod 2$. Furthermore, the walker must be at position $\pm (n-1)$ at time $t - 1$. In next move,
This implies the probability for first hit (assume $t \equiv n \pmod 2$) is given by:
$$\begin{align} P_{hit}(t) &= p P(n-1,t-1) + q P(-n+1,t-1)\\ &= \sum_{r = \lceil\frac{n-t}{2n}\rceil}^{\lfloor\frac{n+t-2}{2n}\rfloor} (-1)^{r} \binom{t-1}{\frac{n+t-2rn}{2} - 1} \left( p^{\frac{t+n}{2}} q^{\frac{t-n}{2}} + q^{\frac{t+n}{2}} p^{\frac{t-n}{2}} \right) \end{align}$$ For $t = n + 2k$, we can simplify this to:
$$P_{hit}(n+2k) = \sum_{-\lfloor\frac{k}{n}\rfloor}^{\lceil\frac{k}{n}\rceil}(-1)^r\binom{n+2k-1}{nr+k}(p^n + q^n) (pq)^k$$