nosas / blog

Personal blog for learning all things AI! (ML/CV/RL) Includes articles, code snippets, and detailed examples.
https://fars.io
2 stars 1 forks source link

Cardinal sensor distances are calculated incorrectly #24

Open nosas opened 2 years ago

nosas commented 2 years ago

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.

nosas commented 2 years ago

Tests are required before closing this issue:

  1. Test cardinal distances
  2. Test cardinal object types
nosas commented 2 years ago

The training map, or even the training process, from issue #27 will be mostly the same