Update app.py
Browse files
app.py
CHANGED
@@ -73,15 +73,20 @@ class ArkanoidEnv(gym.Env):
|
|
73 |
super(ArkanoidEnv, self).__init__()
|
74 |
self.action_space = gym.spaces.Discrete(3) # 0: stay, 1: move left, 2: move right
|
75 |
self.observation_space = gym.spaces.Box(low=0, high=SCREEN_WIDTH, shape=(5 + BRICK_ROWS * BRICK_COLS * 2,), dtype=np.float32)
|
|
|
76 |
self.reset()
|
77 |
|
78 |
-
def reset(self):
|
|
|
|
|
|
|
|
|
79 |
self.paddle = Paddle()
|
80 |
self.ball = Ball()
|
81 |
self.bricks = [Brick(x, y) for y in range(BRICK_HEIGHT, BRICK_HEIGHT * (BRICK_ROWS + 1), BRICK_HEIGHT) for x in range(BRICK_WIDTH, SCREEN_WIDTH - BRICK_WIDTH, BRICK_WIDTH)]
|
82 |
self.done = False
|
83 |
self.score = 0
|
84 |
-
return self._get_state()
|
85 |
|
86 |
def step(self, action):
|
87 |
if action == 0:
|
@@ -154,7 +159,7 @@ def evaluate_model(model):
|
|
154 |
def play_game():
|
155 |
env = ArkanoidEnv()
|
156 |
model = DQN.load("arkanoid_model")
|
157 |
-
obs = env.reset()
|
158 |
done = False
|
159 |
frames = []
|
160 |
while not done:
|
|
|
73 |
super(ArkanoidEnv, self).__init__()
|
74 |
self.action_space = gym.spaces.Discrete(3) # 0: stay, 1: move left, 2: move right
|
75 |
self.observation_space = gym.spaces.Box(low=0, high=SCREEN_WIDTH, shape=(5 + BRICK_ROWS * BRICK_COLS * 2,), dtype=np.float32)
|
76 |
+
self.seed_value = None
|
77 |
self.reset()
|
78 |
|
79 |
+
def reset(self, seed=None, options=None):
|
80 |
+
if seed is not None:
|
81 |
+
random.seed(seed)
|
82 |
+
np.random.seed(seed)
|
83 |
+
self.seed_value = seed
|
84 |
self.paddle = Paddle()
|
85 |
self.ball = Ball()
|
86 |
self.bricks = [Brick(x, y) for y in range(BRICK_HEIGHT, BRICK_HEIGHT * (BRICK_ROWS + 1), BRICK_HEIGHT) for x in range(BRICK_WIDTH, SCREEN_WIDTH - BRICK_WIDTH, BRICK_WIDTH)]
|
87 |
self.done = False
|
88 |
self.score = 0
|
89 |
+
return self._get_state(), {}
|
90 |
|
91 |
def step(self, action):
|
92 |
if action == 0:
|
|
|
159 |
def play_game():
|
160 |
env = ArkanoidEnv()
|
161 |
model = DQN.load("arkanoid_model")
|
162 |
+
obs = env.reset()[0]
|
163 |
done = False
|
164 |
frames = []
|
165 |
while not done:
|