MCPcopy Create free account
hub / github.com/rlcode/reinforcement-learning / render

Method render

1-grid-world/env.py:212–238  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

210 return s
211
212 def render(self):
213 if self.render_mode is None: return
214 if self._screen is None:
215 self._screen = _open(self.title, (WIDTH * DYN_UNIT, HEIGHT * DYN_UNIT + self.HUD))
216 self._hud_font = pygame.font.SysFont(None, 22)
217 self._popup_font = pygame.font.SysFont(None, 28)
218 _pump_events()
219 s, hud = self._screen, self.HUD
220 s.fill(WHITE)
221 pygame.draw.rect(s, (30, 30, 30), pygame.Rect(0, 0, WIDTH * DYN_UNIT, hud))
222 last = f"{self.last_score:+.1f}" if self.last_score is not None else "—"
223 t = self._hud_font.render(
224 f"Episode: {self.episode} Score: {self.score:+.1f} Last Score: {last}",
225 True, (240, 240, 240))
226 s.blit(t, (8, (hud - t.get_height()) // 2))
227 _grid_lines(s, DYN_UNIT, y_off=hud)
228 _circle(s, *self.goal, unit=DYN_UNIT, color=GOAL_COLOR, y_off=hud)
229 for o in self.obstacles:
230 _triangle(s, *o["state"], unit=DYN_UNIT, color=OBSTACLE_COLOR, y_off=hud)
231 rect = _square(s, *self.agent, unit=DYN_UNIT,
232 color=OBSTACLE_COLOR if self._hit > 0 else AGENT_COLOR, y_off=hud)
233 if self._hit > 0:
234 p = self._popup_font.render("-1", True, OBSTACLE_COLOR)
235 s.blit(p, p.get_rect(center=(rect.centerx, rect.top - 14)))
236 self._hit -= 1
237 pygame.display.flip()
238 time.sleep(FPS_DELAY)
239
240
241# ---------------------------------------------------------------------------

Callers 2

resetMethod · 0.95
stepMethod · 0.95

Calls 7

_openFunction · 0.85
_pump_eventsFunction · 0.85
_grid_linesFunction · 0.85
_circleFunction · 0.85
_triangleFunction · 0.85
_squareFunction · 0.85
renderMethod · 0.45

Tested by

no test coverage detected