-
Notifications
You must be signed in to change notification settings - Fork 1
/
action_space.py
executable file
·45 lines (30 loc) · 1011 Bytes
/
action_space.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
from selenium.webdriver.common.keys import Keys
import time
import random
class Action:
def __init__(self, ele, sleep_time):
self.ele = ele
self.sleep_time = sleep_time
def act(self):
raise NotImplementedError()
class Space(Action):
def __init__(self, ele, sleep_time=0.59):
super().__init__(ele, sleep_time)
def act(self):
self.ele.send_keys(Keys.SPACE)
time.sleep(self.sleep_time)
return 0
class NoAction(Action):
def __init__(self, ele, sleep_time=0.02):
super().__init__(ele, sleep_time)
def act(self):
time.sleep(self.sleep_time)
return 1
class ActionSpace:
def __init__(self, ele, space_sleep=0.59, no_action_sleep=0.02):
self.space = Space(ele, space_sleep)
self.no_action = NoAction(ele, no_action_sleep)
self.actions = [self.space, self.no_action]
def sample(self):
action = random.choice(list(range(len(self.actions))))
return action