(self)
| 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 | # --------------------------------------------------------------------------- |
no test coverage detected