diff --git a/mesa/examples/basic/boid_flockers/agents.py b/mesa/examples/basic/boid_flockers/agents.py index 2ff00cbaef2..a8f23f915aa 100644 --- a/mesa/examples/basic/boid_flockers/agents.py +++ b/mesa/examples/basic/boid_flockers/agents.py @@ -58,7 +58,8 @@ def __init__( def step(self): """Get the Boid's neighbors, compute the new vector, and move accordingly.""" - self.neighbors = self.model.space.get_neighbors(self.pos, self.vision, False) + neighbors = self.model.space.get_neighbors(self.pos, self.vision, True) + self.neighbors = [n for n in neighbors if n is not self] # If no neighbors, maintain current direction if not self.neighbors: diff --git a/mesa/space.py b/mesa/space.py index 6e15426bf34..d503d42e41b 100644 --- a/mesa/space.py +++ b/mesa/space.py @@ -1415,6 +1415,13 @@ def get_neighbors( coordinates. i.e. if you are searching for the neighbors of a given agent, True will include that agent in the results. + + Notes: + If 1 or more agents are located on pos, include_center=False will remove all these agents + from the results. So, if you really want to get the neighbors of a given agent, + you should set include_center=True, and then filter the list of agents to remove + the given agent (i.e., self when calling it from an agent). + """ if self._agent_points is None: self._build_agent_cache()