Newer
Older
import random as rd
import numpy as np
import matplotlib.pyplot as plt
from tmc import TransitionMatrixCalculator as tmc
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class EmpiricalComparision :
def __init__(self) :
return
def simulation(strategy, layout : list, circle, nIter : int) :
tmc_instance = tmc()
safe_dice = tmc_instance._compute_safe_matrix(layout, circle)
normal_dice = tmc_instance._compute_normal_matrix(layout, circle)
risky_dice = tmc_instance._compute_risky_matrix(layout, circle)
matrices_transition = [safe_dice, normal_dice, risky_dice]
nTurns = []
turns = 0
for _ in range(nIter) :
turns = 0
k = 0
while k < len(layout)-1 :
action = strategy[k]
transitionMatrix = matrices_transition[int(action -1)]
k = np.rd.choice(len(layout), p = transitionMatrix[k])
if layout[k] == 3 and action == 2 :
turns +=1 if np.rd.uniform(0,1) < 0.5 else 2
elif layout[k] == 3 and action == 3 :
turns += 2
else :
turns += 1
nTurns.append(turns)
return np.mean(nTurns)
def plot(layouts : list, circle, nIter : int) :
Markov = []
Safe = []
Normal = []
Risky = []
Random = []
for layout in layouts :
expec, policy = mD(layout, circle)
# Simulate the game
return
layout = [0,0,3,0,0,0,2,0,0,0,3,0,0,1,0]
results(layout, False, 1000000)
results(layout, True, 1000000)