-
Notifications
You must be signed in to change notification settings - Fork 0
/
MySearchModel.py
56 lines (45 loc) · 1.61 KB
/
MySearchModel.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
import time
import gym
import constants
from RGBState import RGBState
class MySearchModel(object):
def __init__(self, searchspace):
self.searchspace = searchspace
self.env = gym.make(constants.GAMES[8])
#print self.env._action_set
self.env._obs_type = 'image'
self.env.reset()
self.env.frameskip = constants.FRAMESKIP
self.root = self.make_root_node()
def init(self):
self.env.reset()
ale_state = self.env.ale.cloneState()
screen = self.env._get_obs()
state = RGBState(ale_state)
state.set_features(screen)
return state
def is_goal(self, node):
return node.state.reward > constants.GOAL_SCORE
def get_successor_states(self, state):
return state.get_successor_states(self.env)
def make_root_node(self):
return self.searchspace.make_root_node(self.init())
def make_node(self, parent, action, state):
return self.searchspace.make_child_node(parent, action, state)
def show_env(self):
self.env.render()
time.sleep(2)
self.env.render(close=True)
def simulate_actions(self, actions):
self.env.reset()
for act in actions:
print "\tAction: %s" % str(act)
self.env.step(act)
self.show_env()
def successor_nodes(self, node):
successors = []
for action, state in self.get_successor_states(node.state):
successors.append(self.searchspace.make_child_node(node, action, state))
return successors
def get_features(self, node):
return node.state.features