Proof in ruin player problem 
Let $M_i$ the average number of matches until the player, or lose all,
  or wins the capital $N$ as it began with the capital $i$. Show that
  $$M_i=i(N-1);p=\frac{1}{2}$$
  $$M_i=\frac{i}{1-2p}-\frac{N}{1-2p}\frac{1-(\frac{1-p}{p})^i}{1-(\frac{1-p}{p})^N};p\neq\frac{1}{2}$$

I'm litle lost but I believe we need to assume that
$$P_{WIN}=P_{LOSE}=\frac{1}{2}$$
in each match. Let $X_n$ the Markov Chain to denote the amount of capital in after $n$ matches, then since they start with $i$
$$P(X_{n+1}=i+1|X_n=i)=\frac{1}{2}$$
$$P(X_{n+1}=i-1|X_n=i)=\frac{1}{2}$$
I need to calculate the expectation here?
 A: By the law of total probability, we have $$M_i=1+p M_{i+1} + (1-p) M_{i-1},$$ with $M_0=M_n=0$. 
It can now be shown that the given solution is the answer to the above recursion. I believe the recursion can be solved along the following lines. But it seemed tedious.
To solve the homogenous case $M_i=p M_{i+1} + (1-p) M_{i-1}$, we write $$p(M_{i+1}-M_i)=(1-p)(M_i-M_{i-1}).$$Let $\delta_i = M_i - M_{i-1}$ to get
$$\delta_{i+1}=\frac{1-p}p\delta_i$$ and $\delta_1 = M_1$. We also have $\sum\delta_i=M_N-M_0=0$. So we can solve for $M_1$ and find the other $M_i$ as well.
Update: I made corrections based on the comment below, but did not complete the solution of the recursive equation.
A: You do not assume that the probability of losing is equal to the probability of winning; the first line you have given is the formula for a fair game, i.e. when the probability of winning is equal to the probability of winning, i.e. $p=\frac{1}{2}$ as written after the semicolon, whereas the second line is for when $p \neq \frac{1}{2}$.
(The player is betting 1 unit at a time, from what I gather.)
First off, I believe that for a fair game, the solution should in fact be $M_i = i(N-i)$. (Check the boundary condition when the player starts off with capital $N$; then $M_i$ should be zero.)
Moving on, we can denote the time before the player hits $0$ or $N$, starting from $i$, in one random realisation of the game, by $\tau_i$. Then $M_i = \mathbb E [\tau_i]$, and use a first-step decomposition:
$$M_i = 1 + (1-p) M_{i-1} + p M_{i+1}$$
This is a difference equation with boundary conditions $M_0=M_N=0$.
For the fair case when $p = \frac{1}{2}$, $$M_i=A+Bi-i^2$$ is the general solution (you should check this!); by the BCs, $A=0$ and $B=N$, which gives you the first required solution.
For when $p\neq \frac{1}{2}$, the general solution is $$M_i = \frac{i}{1-2p} + A + B \left( \frac {1-p}{p}\right)^i$$
and this should lead you to the second required solution after considering the BCs.
Alternatively: as this is a 'show' problem, it is sufficient for you to just check that the given expressions for $M_i$ satisfy the difference equation (i.e. plug it in), which is probably what you are expected to do!
