text_plain_output_1.png
import numpy as np # linear algebra

states = {-1: 'Loss', 0: 'Draw', 1: 'Win'}
states

transition = np.array([[0.65, 0.1, 0.25], [0.3, 0.5, 0.2], [0.35, 0.1, 0.55]])
transition

n = 15
br = 0
points = 0
start_state = 0
prev_state = start_state
while n:
    if prev_state == 0:
        points += 1
    elif prev_state == 1:
        points += 3
    curr_state = np.random.choice([-1, 0, 1], p=transition[prev_state + 1])
    prev_state = curr_state
    n -= 1
    br += 1
if prev_state == 0:
    points += 1
elif prev_state == 1:
    points += 3

n = 100000
br = n
br_l = 0
br_d = 0
br_w = 0
start_state = 0
prev_state = start_state
while n:
    curr_state = np.random.choice([-1, 0, 1], p=transition[prev_state + 1])
    if curr_state == -1:
        br_l += 1
    elif curr_state == 0:
        br_d += 1
    else:
        br_w += 1
    prev_state = curr_state
    n -= 1

steps = 10 ** 6
start_state = 0
pi = np.array([0, 0, 0])
pi[start_state + 1] += 1
prev_state = start_state
for i in range(steps):
    curr_state = np.random.choice([-1, 0, 1], p=transition[prev_state + 1])
    pi[curr_state + 1] += 1
    prev_state = curr_state

pi = left[:, 0]
pi_normalized = [(x / np.sum(pi)).real for x in pi]

steps = 10 ** 6
start_state = 0
pi = transition[start_state + 1]
for i in range(steps):
    pi = np.dot(pi, transition)

steps = 10
transition_n = transition
for i in range(steps):
    transition_n = np.matmul(transition_n, transition)
print('Matrix: \n', transition_n, '\n')
print('pi = ', transition_n[1])