-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
82 lines (68 loc) · 2.07 KB
/
main.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
import gym
import numpy as np
import matplotlib.pyplot as plt
from MCTSDNN.MCTSDNN import MCTSDNN
from GameManager import GameManager
size = 5
env = gym.make('gym_go:go-v0', size=size, komi=0, reward_method='real')
gm = GameManager(env)
noTree = MCTSDNN(env, size, "Go")
noTree.train(10)
withTree = MCTSDNN(env, size, "Go" )
withTree.train(10)
noTreeWins = 0
withTreeWins = 0
draws = 0
for i in range(0,100):
print("Game: ", i)
env.reset()
noTree.reset()
withTree.reset()
done = False
while not done:
# Every second game switch starting player
if( i % 2 == 0):
action = noTree.take_turn_play()
_, _, done, _ = env.step(action)
env.render('terminal')
withTree.opponent_turn_update(action)
if done:
break
action = withTree.take_turn()
_, _, done, _ = env.step(action)
env.render('terminal')
noTree.opponent_turn_update(action)
else:
action = withTree.take_turn()
_, _, done, _ = env.step(action)
env.render('terminal')
noTree.opponent_turn_update(action)
if done:
break
action = noTree.take_turn_play()
_, _, done, _ = env.step(action)
env.render('terminal')
withTree.opponent_turn_update(action)
if i % 2 == 0:
if env.winner() == 1:
noTreeWins += 1
elif env.winner() == -1:
withTreeWins += 1
else:
draws += 1
else:
if env.winner() == -1:
noTreeWins += 1
elif env.winner() == 1:
withTreeWins += 1
else:
draws += 1
# Plot the results in a bar graph
objects = ('No Tree', 'With Tree', 'Draws')
y_pos = np.arange(len(objects))
performance = [noTreeWins, withTreeWins, draws]
plt.bar(y_pos, performance, align='center', alpha=0.5)
plt.xticks(y_pos, objects)
plt.ylabel('Wins')
plt.title('Wins with and without tree')
plt.show()