MCPcopy Index your code
hub / github.com/lazyprogrammer/machine_learning_examples / Env

Class Env

rl3/es_flappy.py:25–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23
24
25class Env:
26 def __init__(self):
27 self.game = FlappyBird(pipe_gap=125)
28 self.env = PLE(self.game, fps=30, display_screen=False)
29 self.env.init()
30 self.env.getGameState = self.game.getGameState # maybe not necessary
31
32 # by convention we want to use (0,1)
33 # but the game uses (None, 119)
34 self.action_map = self.env.getActionSet() #[None, 119]
35
36 def step(self, action):
37 action = self.action_map[action]
38 reward = self.env.act(action)
39 done = self.env.game_over()
40 obs = self.get_observation()
41 # don't bother returning an info dictionary like gym
42 return obs, reward, done
43
44 def reset(self):
45 self.env.reset_game()
46 return self.get_observation()
47
48 def get_observation(self):
49 # game state returns a dictionary which describes
50 # the meaning of each value
51 # we only want the values
52 obs = self.env.getGameState()
53 return np.array(list(obs.values()))
54
55 def set_display(self, boolean_value):
56 self.env.display_screen = boolean_value
57
58
59# make a global environment to be used throughout the script

Callers 1

es_flappy.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected