-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample_run.py
136 lines (130 loc) · 3.63 KB
/
sample_run.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
from utilities import MrX,detective,observation,graph_utils
import numpy as np
import matplotlib.pyplot as plt
import game
from utilities import mcts
#
reward_x,victory = [],0
reward_d=[]
l=[]
l1=[]
l2=[]
for it in range(0,2000):
# Start the run
G = game.game()
type = ["detective","x"]
hide_move = [3,6,9]
multi_move = []
#print("\n ################### START GAME ########################################")
#print(G.M)
while(not G.finish()):
move_no = G.move
#print("List of actions ", G.X.list_actions(G.board,G.detectives))
#print("\nMove No", move_no + 1, "Start -------------------------------------------------------------- \n")
if(move_no in hide_move):
(_,rew,_,_)=G.take_action(None,type[1],[4],0,"random")
#print('\n')
elif(move_no in multi_move):
#print("Multi Move")
(_,rew,_,_)=G.take_action(None,type[1],[3],0,"random")
#print('\n')
else:
(_,rew,_,_)=G.take_action(None,type[1],[],0,"random")
#print("\n")
for i in range(0,4):
#print("Detective ", i, "taking action .. ")
(_,rew,_,_)=G.take_action(None,type[0],[],i,"random")
#print("\n")
G.update_fv()
#print(G.f_x_action((2,24)).shape)
#G.print_pos()
#G.print_reward()
#print("\nMove No" ,move_no+1, "Over -------------------------------------------------------------- \n")
reward_x.append(G.X_reward)
reward_d.append(G.D_reward)
if(G.move >= 19):
victory+=1
if it>0:
l.append((len(l)*l[len(l)-1]+1)/(len(l)+1))
else:
l.append(1)
else:
if it>0:
l.append((len(l)*l[len(l)-1])/(len(l)+1))
else:
l.append(0)
if it>0:
l1.append((len(l1)*l[len(l1)-1]+G.X_reward)/(len(l1)+1))
l2.append((len(l2)*l[len(l2)-1]+G.D_reward)/(len(l2)+1))
else:
l1.append(G.X_reward)
l2.append(G.D_reward)
print(victory,np.mean(reward_x))
plt.figure(0)
plt.plot(l1[100:])
plt.xlabel("Run")
plt.ylabel("Mean Reward for X")
zt=[]
for jt in range(41):
zt.append(-1+jt*0.05)
# plt.title("Reward for X with Random Policies")
y_axis = [x for x in range(-15,25,5)]
x_axis = [x for x in range(1,2001,100)]
#plt.yticks(zt)
plt.xticks(x_axis)
plt.savefig("Result.png")
plt.figure(1)
plt.plot(l[100:])
plt.xlabel("Run")
plt.ylabel("Win ratio for X")
zt=[]
for jt in range(41):
zt.append(jt*0.025)
# plt.title("Reward for X with Random Policies")
#y_axis = [x for x in range(0,1,0.05)]
x_axis = [x for x in range(1,2001,100)]
#plt.yticks(zt)
plt.xticks(x_axis)
plt.savefig("Result1.png")
plt.figure(2)
plt.plot(l2[100:])
plt.xlabel("Run")
plt.ylabel("Mean Reward for D")
zt=[]
for jt in range(41):
zt.append(jt*0.025)
# plt.title("Reward for X with Random Policies")
#y_axis = [x for x in range(0,1,0.05)]
x_axis = [x for x in range(1,2001,100)]
#plt.yticks(zt)
plt.xticks(x_axis)
plt.savefig("Result2.png")
plt.figure(3)
plt.plot(reward_x[100:])
plt.xlabel("Run")
plt.ylabel("Reward for X")
zt=[]
for jt in range(41):
zt.append(jt*0.025)
# plt.title("Reward for X with Random Policies")
#y_axis = [x for x in range(0,1,0.05)]
x_axis = [x for x in range(1,2001,100)]
#plt.yticks(zt)
plt.xticks(x_axis)
plt.savefig("Result3.png")
plt.figure(4)
plt.plot(reward_d[100:])
plt.xlabel("Run")
plt.ylabel("Reward for D")
zt=[]
for jt in range(41):
zt.append(jt*0.025)
# plt.title("Reward for X with Random Policies")
#y_axis = [x for x in range(0,1,0.05)]
x_axis = [x for x in range(1,2001,100)]
#plt.yticks(zt)
plt.xticks(x_axis)
plt.savefig("Result4.png")
print(l)
print(l1)
print(l2)