-
Notifications
You must be signed in to change notification settings - Fork 263
/
welcome.py
36 lines (28 loc) · 841 Bytes
/
welcome.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
import numpy as np
from tensorflow.python import keras as K
import gym
import gym_ple
def welcome():
"""
Code to check installation of basic libraries
"""
env = gym.make("Catcher-v0")
num_action = env.action_space.n
episode_count = 10
s = env.reset()
brain = K.Sequential()
brain.add(K.layers.Dense(num_action, input_shape=[np.prod(s.shape)],
activation="softmax"))
def policy(s):
evaluation = brain.predict(np.array([s.flatten()]))
return np.argmax(evaluation)
for e in range(episode_count):
s = env.reset()
done = False
while not done:
env.render(mode="human")
a = policy(s)
n_state, reward, done, info = env.step(a)
s = n_state
if __name__ == "__main__":
welcome()