Expected number of wins in a higher/lower number guessing game Rules of the game:

*

*Before each turn, the player guesses either "higher" or "lower".

*On each turn, an integer $0 <= n_t <= 100$ is selected randomly and uniformly.

*

*

*If $n_t$ is greater than the $n$ from the previous turn (i.e. $n_t > n_{t-1}$), and the player guessed "higher", then the player wins.

*If $n_t < n_{t-1}$, and the player guessed "lower", then the player wins.

*Otherwise, the player loses.



For the very first turn ($t = 1$), $n_0 = 0$ (arbitrarily chosen).
The player uses this strategy to play the game:

*

*If $n_{t-1} < 50$, guess "higher".

*If $n_{t-1} > 50$, guess "lower".

*If $n_{t-1} = 50$, toss a fair coin, guess "higher" if heads, and guess "lower" if tails.

My questions are:

*

*Suppose the player uses the strategy above to play the game for 100 turns. What is the expected number of wins?

*Would the expected number of wins be different if $n_0$ was some other number (e.g. $n_0 = 50$)?

*Would the expected proportion of wins be different if there were more turns (e.g. 100,000 turns instead of 100 turns)?

I used the Python script below to get an approximate answer to question 1. It simulates 100,000 games of 100 turns each, with $n_0 = 0$. The average number of wins seems to be around $74.7$. I get a similar answer when I use NumPy's random number generator (n = np.random.randint(0, 101)) instead of the one in Python's standard library. How should I approach the problem if I want an analytical solution instead?
import random
import statistics

game_results = []

# 100,000 games.
for _ in range(100_000):
    num_wins = 0

    previous_n = 0
    guess_higher = True

    # 100 turns per game.
    for _ in range(100):
        # Player's strategy.
        if previous_n < 50:
            guess_higher = True
        elif previous_n > 50:
            guess_higher = False
        elif previous_n == 50:
            guess_higher = random.choice([True, False])

        n = random.randint(0, 100)  # Inclusive of 0 and 100.

        if ((n > previous_n and guess_higher) or
            (n < previous_n and not guess_higher)):
            num_wins += 1

        previous_n = n

    game_results.append(num_wins)

print('Average number of wins:', statistics.mean(game_results))
print('Sample variance:', statistics.variance(game_results))

 A: Let $\ W_t=1\ $ if the player wins the $\ t^\text{th}\ $ round and $\ W_t=0\ $ otherwise. Then the total number of wins in $\ 100\ $ rounds is $\ \sum_\limits{t=1}^{100}W_t\ $ and the expected number of wins is $\ \sum_\limits{t=1}^{100}\mathbb{E}\big(W_t\big)\ $. Now
\begin{align}
\mathbb{E}\big(W_t\big)&=\mathbb{E}\big(\mathbb{E}\big(W_t\,\big|\,n_{t-1}\big)\big)\\
&=\mathbb{E}\big(P\big(W_t=1\,\big|\,n_{t-1}\big)\big)\\
\end{align}
for $\ t\ge2\ $,
\begin{align}
\mathbb{E}\big(W_1=1\big)&=P\big(W_1=1\big)\\
&=\cases{
\frac{100-n_0}{101}&if $\ n_0\le50$\\
\frac{n_0-1}{101}&if $\ n_0>50$}\ ,
\end{align}
and
\begin{align}
P\big(W_t=1\,|n\,_{t-1}\big)&=\cases{\frac{100-n_{t-1}}{101}&if $\ n_{t-1}\le50$\\
\frac{n_{t-1}-1}{101}&if $\ n_{t-1}>50$}
\end{align}
for $\ t\ge2\ $. Therefore
\begin{align}
\mathbb{E}\big(W_t\big)&=\mathbb{E}\big(\mathbb{E}\big(W_t\,|\,n_{t-1}\big)\big)\\
&=
\frac{1}{101^2}\Bigg(\sum_{n=0}^{50}(100-n)+\sum_{n=51}^{101}(n-1)\Big)\\
&=\frac{\displaystyle2\sum_{n=50}^{100}n}{101^2}\\
&=\frac{51\cdot150}{101^2}
\end{align}
for $\ t\ge2\ $, and so
\begin{align}
\mathbb{E}\Big(\sum_{t=1}^{100}W_t\Big)&=\mathbb{E}\big(W_1\big)+\frac{99\cdot51\cdot150}{101^2}\\
&=\cases{\frac{100-n_0}{101}+\frac{99\cdot51\cdot150}{101^2}&if $\ n_0\le50$\\
\frac{n_0-1}{101}+\frac{99\cdot51\cdot150}{101^2}&if $\ n_0>50$}\ .
\end{align}
For $\ n_0=0\ $, this gives the expected number of wins to be
$$
\frac{100}{101}+\frac{99\cdot51\cdot150}{101^2}\approx75.2\ .
$$
