-
Notifications
You must be signed in to change notification settings - Fork 0
/
env_100.py
103 lines (82 loc) · 2.57 KB
/
env_100.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from interrupt import Macro as mc
import image_matching2 as im
class env():
def __init__(self):
self.actions = []
self.actions.append(0)
self.pre_score = 0
'''
Test codes~~~~~~
this should be changed to variables version
def __init__(self,observations which is cv image matched data,actions which is macros):
'''
### observation_space
self.observation_space = im.get_shape()
self.time_step = 0;
self.best_time_step = 0;
self.is_alive = True
### actions
macros = []
macro1 = mc.Macro()
macro2 = mc.Macro()
# new_macro.setDelay(3)
macro1.setKeyPress('left')
macros.append(macro1)
macro2.setKeyPress('right')
macros.append(macro2)
# new_macro.setDelay(3)
# macros.append(macro2)
'''
test codes
end here
'''
self.actions.append(macro1)
self.actions.append(macro2)
def set_actions(self, macros):
'''
set actions
for test this is temporary func
'''
self.actions = macros
def step(self, action_num):
### should really think about how game over is recongnized
# self.is_alive, next_state = get_state()#Capture
### should really think about how game over is recongnized
self.time_step+=1
if(action_num>0):#do nothing if no op
self.actions[action_num].runMacro()
score = 0
'''
score = get_score_from_ocr
'''
# print("t = ",self.time_step)
# print("best_t = ",self.best_time_step)
# if(pre_score < score):
# reward = 1
# elif(pre_score == score):
# reward = 0
# else:
# reward = -1
# pre_score = score;
#reward = 0 # get from ocr
done, next_state = im.get_state()#Capture
if(self.time_step>self.best_time_step):
reward = 1
elif(self.time_step>int(self.best_time_step*0.75)):
reward = abs(self.time_step)/self.best_time_step
elif(done):
reward = -1
else:
reward = 0
if(done):
self.best_time_step = max(self.best_time_step,self.time_step)
return (next_state, reward, done, 0)
def reset(self):
reset_macro = mc.Macro()
# self.pre_score = 0
reset_macro.setMouseClick('left')
reset_macro.runMacro();
self.time_step = 0
self.is_alive = True
_, state = im.get_state()
return state