-
Notifications
You must be signed in to change notification settings - Fork 0
/
play.py
33 lines (24 loc) · 774 Bytes
/
play.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
import gym
from DQNAgent import DQNAgent
from numpy import reshape
env = gym.make('CartPole-v0')
env._max_episode_steps = 100000
state_size = env.observation_space.shape[0]
action_size = env.action_space.n
load_model = True
episodes = 5000
agent = DQNAgent(state_size, action_size, load_model)
for e in range(episodes):
state = env.reset()
state = reshape(state, [1, state_size])
done = False
time = 0
while not done:
env.render()
action = agent.act(state)
state, _ , done, _ = env.step(action)
state = reshape(state, [1, state_size])
time += 1
if done:
print("episode: {}/{}, score: {}".format(e, episodes, time))
break