The function _find_nearest_collision in sensor.py is calculating the distance from the Wall's midpoint.
Instead, we should calculate the difference between the Agent's position and y values for North/South and x values for East/West. Like so...
for obj in self._collisions:
obj_rect_coord = {
"N": pg.Vector2(self.agent.pos.x, obj.rect.bottom),
"S": pg.Vector2(self.agent.pos.x, obj.rect.top),
"E": pg.Vector2(obj.rect.left, self.agent.pos.y),
"W": pg.Vector2(obj.rect.right, self.agent.pos.y),
}
This explains why my Agents were continuously running into walls even though I discouraged that behavior in the GameEnv reward function lol. RL is fun. Agents are good at finding these edge cases.
The function
_find_nearest_collision
in sensor.py is calculating the distance from the Wall's midpoint. Instead, we should calculate the difference between the Agent's position andy
values for North/South andx
values for East/West. Like so...This explains why my Agents were continuously running into walls even though I discouraged that behavior in the
GameEnv
reward function lol. RL is fun. Agents are good at finding these edge cases.