eugenevinitsky / sequential_social_dilemma_games

Repo for reproduction of sequential social dilemmas
MIT License
377 stars 134 forks source link

Vectorize map to rgb #143

Open eugenevinitsky opened 5 years ago

eugenevinitsky commented 5 years ago

The current map to rgb is two nested for loops; this can totally be vectorized.

internetcoffeephone commented 4 years ago

Made redundant in https://github.com/eugenevinitsky/sequential_social_dilemma_games/pull/179.

Instead of calling map to rgb all the time, a zero-padded graphical map (MapEnv.world_map_color) is maintained next to the logical map (MapEnv.world_map). To make updates to the world map, you must now go through a function that also updates the color map.

As updates to the graphical map are thus made whenever necessary, we no longer need a full re-render on every single frame. This saves a lot of computational power, but is more change-error-prone, mainly due to special case handling like beams overlaying agents.

To generate observations, appropriately rotated and bounded numpy slices/views are taken from world_map_color. This is very fast because the observations aren't copied in memory, each observation is just a few pointers to the world map.