-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQlearningtest.py
More file actions
78 lines (42 loc) · 1.43 KB
/
Qlearningtest.py
File metadata and controls
78 lines (42 loc) · 1.43 KB
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
from soccersimulator import Strategy, SoccerAction, Vector2D, SoccerTeam, Simulation, show_simu
from soccersimulator.settings import*
import numpy as np
import numpy.linalg as la
import math
from pinkertons import *
import pickle as pkl
# Strategy
QTestStrategy = QStrategy()
#QTestStrategy.add("defance",DefonceurStrategy())
QTestStrategy.add("attaque",FonceurStrategy())
QTestStrategy.add("wing d",CoteStrategyd())
QTestStrategy.add("wing g",CoteStrategyg())
'''
QTestStrategy = QStrategy.QStrategy()
QTestStrategy.add("right",SimpleStrategy(shoot_right,""))
QTestStrategy.add("left",SimpleStrategy(shoot_left,""))
QTestStrategy.add("up",SimpleStrategy(shoot_up,""))
QTestStrategy.add("down",SimpleStrategy(shoot_down,""))
'''
#Learning
expe = QLearning(strategy = QTestStrategy,monte_carlo=False )
expe.start(fps =1500)
with open( "qstrategy.pkl","wb") as fo:
QTestStrategy.qtable = expe.qtable
print('Q TABLE', expe.qtable)
pkl.dump(QTestStrategy,fo)
#Test
#with open("qstrategy.pkl","rb") as fi:
# QStrategy = pkl.load(fi)
# Simulate and display the match
#simu = RandomPos(QStrategy)
team1 = SoccerTeam(name="Team 1")
team2 = SoccerTeam(name="Team 2")
team1.add("Attaquant", QTestStrategy)
team1.add("Attaquant2", QTestStrategy)
team2.add("wing g", Strategy())
team2.add("wing d", Strategy()) # Random strategy
simu = Simulation(team1, team2)
#simu.start()
show_simu(simu)
expe.get_res()