-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtrain.py
executable file
·57 lines (44 loc) · 1.27 KB
/
train.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
#!/usr/bin/python3
from game.play import Pair, Game
from players.PlayerRandom import PlayerRandom
from players.PlayerKeyboard import PlayerKeyboard
from players.PlayerRL import PlayerRL
import stdout
# RL par
# TODO save & load policy networks
# TODO share policy networks across all RL players
playerA1 = PlayerRL("Borna")
playerA2 = PlayerRL("Mislav")
pairA = Pair(playerA1, playerA2)
# Par koji igra nasumično
playerB1 = PlayerRandom("Luka")
playerB2 = PlayerRandom("Lovro")
pairB = Pair(playerB1, playerB2)
# Treniraj
stdout.disable()
games = 10000
last = 100
wins = list()
for i in range(games):
game = Game(pairA, pairB)
pointsA, pointsB = game.play()
wins.append("A" if pointsA > pointsB else "B")
if i > 0 and i % last == 0:
winsA = wins[-last:].count("A")
winningPercentage = winsA / last * 100
# if winningPercentage >= 90:
# break
stdout.enable()
print("[RL] {} - postotak pobjeda (u zadnjih {} igara): {}% ({} / {})".format(pairA, last, winningPercentage, winsA, last))
stdout.disable()
# Igraj
stdout.enable()
playerA1.eval()
playerA2.eval()
playerMe = PlayerKeyboard("Ja")
playerFriend = PlayerRandom("On")
game = Game(
Pair(playerMe, playerFriend),
pairA
)
pointsA, pointsB = game.play()