Newer
Older
1
2
3
4
5
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
import matplotlib.pyplot as plt
from simulate import Validation as Val
from tmc import TransitionMatrixCalculator as tmc
from markovDecision import MarkovDecisionSolver as mD
import random as rd
import numpy as np
def plot_results(layouts, circle, n_iterations=100):
results_markov = []
results_safe = []
results_normal = []
results_risky = []
results_random = []
for layout in layouts:
# Compute optimal policy
expec, policy = mD(layout, circle)
# Simulate game
result_markov = Val.simulate_game(policy, layout, circle, n_iterations)
results_markov.append(result_markov)
result_safe = Val.simulate_game([1]*15, layout, circle, n_iterations)
results_safe.append(result_safe)
result_normal = Val.simulate_game([2]*15, layout, circle, n_iterations)
results_normal.append(result_normal)
result_risky = Val.simulate_game([3]*15, layout, circle, n_iterations)
results_risky.append(result_risky)
result_random = Val.simulate_game(np.random.randint(1, 4, size=15), layout, circle, n_iterations)
results_random.append(result_random)
# Plot the results
plt.figure(figsize=(12, 8))
plt.plot(range(len(layouts)), results_markov, label='Markov')
plt.plot(range(len(layouts)), results_safe, label='Safe')
plt.plot(range(len(layouts)), results_normal, label='Normal')
plt.plot(range(len(layouts)), results_risky, label='Risky')
plt.plot(range(len(layouts)), results_random, label='Random')
plt.xticks(range(len(layouts)), range(len(layouts)))
plt.xlabel('Layout number', fontsize=13)
plt.ylabel('Average number of turns', fontsize=13)
plt.legend(loc='upper left', bbox_to_anchor=(1, 1), ncol=1)
plt.show()