Describe the bug
Context: #1508 (comment)
Currently, calling place_agent twice or more in a row without calling remove_agent beforehand causes the agent to exist in several locations.
Expected behavior
An error should be raised if an agent's pos attribute is not None, when calling place_agent.
A stronger guarantee would be to check the entire grid for the existence of the agent, but this is very costly to do, unless there is a dict attribute for the grid to track the agents existence.
To Reproduce
import mesa
a = mesa.Agent(0, None)
grid = mesa.space.SingleGrid(3, 3, False)
grid.place_agent(a, (1, 1))
print("a.pos", a.pos)
grid.place_agent(a, (0, 0))
print("a.pos", a.pos)
for e in grid.coord_iter():
print(e)
Output
a.pos (1, 1)
a.pos (0, 0)
(<mesa.agent.Agent object at 0x7ffa9311a9e0>, 0, 0)
(None, 0, 1)
(None, 0, 2)
(None, 1, 0)
(<mesa.agent.Agent object at 0x7ffa9311a9e0>, 1, 1)
(None, 1, 2)
(None, 2, 0)
(None, 2, 1)
(None, 2, 2)