diff --git a/environments/factory/renderer.py b/environments/factory/renderer.py index ff4a58f..48868b4 100644 --- a/environments/factory/renderer.py +++ b/environments/factory/renderer.py @@ -2,6 +2,7 @@ import sys import numpy as np from pathlib import Path from collections import deque +from itertools import product import pygame from typing import NamedTuple, Any import time @@ -76,16 +77,16 @@ class Renderer: def visibility_rects(self, bp, view): rects = [] - for i in range(-self.view_radius, self.view_radius+1): - for j in range(-self.view_radius, self.view_radius+1): - if bool(view[self.view_radius+j, self.view_radius+i]): - visibility_rect = bp['dest'].copy() - visibility_rect.centerx += i*self.cell_size - visibility_rect.centery += j*self.cell_size - shape_surf = pygame.Surface(visibility_rect.size, pygame.SRCALPHA) - pygame.draw.rect(shape_surf, self.AGENT_VIEW_COLOR, shape_surf.get_rect()) - shape_surf.set_alpha(64) - rects.append(dict(source=shape_surf, dest=visibility_rect)) + for i, j in product(range(-self.view_radius, self.view_radius+1), + range(-self.view_radius, self.view_radius+1)): + if bool(view[self.view_radius+j, self.view_radius+i]): + visibility_rect = bp['dest'].copy() + visibility_rect.centerx += i*self.cell_size + visibility_rect.centery += j*self.cell_size + shape_surf = pygame.Surface(visibility_rect.size, pygame.SRCALPHA) + pygame.draw.rect(shape_surf, self.AGENT_VIEW_COLOR, shape_surf.get_rect()) + shape_surf.set_alpha(64) + rects.append(dict(source=shape_surf, dest=visibility_rect)) return rects def render(self, entities):