-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultithread.py
More file actions
62 lines (56 loc) · 1.37 KB
/
Copy pathmultithread.py
File metadata and controls
62 lines (56 loc) · 1.37 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
50
51
52
53
54
55
56
57
58
59
60
61
62
import Env_Game as env
import numpy as np
from PIL import ImageOps
from PIL import Image
from time import sleep
import threading
RESIZE = 84
np.set_printoptions(threshold=np.nan)
def preprocess(arr):
#returns preprocessed image
return np.asarray(ImageOps.mirror(Image.fromarray(arr).rotate(270)).convert('L').resize((RESIZE, RESIZE)))
class Game(threading.Thread):
def __init__(self, render):
threading.Thread.__init__(self)
self.render = render
def run(self):
e = env.Env(self.render)
e.reset()
d = False
while not d:
a = np.random.randint(0, 5)
sleep(0.05)
o, r, d, _ = e.step(a)
if d:
print(preprocess(o).shape)
"""
e = env.Env(True)
e.reset()
d = False
while not d:
a = np.random.randint(0, 5)
sleep(0.05)
o, r, d, _ = e.step(a)
if d:
print(preprocess(o).shape)
"""
g1 = Game(True)
g2 = Game(False)
g3 = Game(False)
g4 = Game(False)
g1.start()
g2.start()
g3.start()
g4.start()
"""
while(True):
a = np.random.randint(0, 5)
sleep(0.05)
o, r, d, _ = Env.step(a)
im = ImageOps.mirror(Image.fromarray(o).rotate(270)).convert('L').resize((RESIZE, RESIZE))
im_arr = np.asarray(ImageOps.mirror(Image.fromarray(o).rotate(270)).convert('L').resize((RESIZE, RESIZE)))
if d:
im.show()
sleep(5)
break
"""