Skip to content

Commit 2e282e1

Browse files
authored
Make agent move to actual random closest position (#2119)
This fixes a bug in which move_agent_to_one_of is deterministic when pos has multiple closest choices and selection="closest".
1 parent 84b41a2 commit 2e282e1

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

mesa/space.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ def move_agent_to_one_of(
461461
# Find the closest position without sorting all positions
462462
closest_pos = None
463463
min_distance = float("inf")
464+
agent.random.shuffle(pos)
464465
for p in pos:
465466
distance = self._distance_squared(p, current_pos)
466467
if distance < min_distance:

0 commit comments

Comments
 (0)