MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / Env

Class Env

rl3/flappy2envs.py:19–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

flappy2envs.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected