projectmesa/mesa

move_agent_to_one_of is deterministic when pos has multiple closest choices and selection="closest"

OrenBochman opened this issue · 0 comments

Describe the bug

move_agent_to_one_of is deterministic when pos has multiple closest choices and selection="closest"

Expected behavior

expected that when using move_agent_to_one_of() in a sugarscape agent's motion will be random within a sugar plateau for low vision agents, but noticed that such agents now exhibit periodic motion.

To Reproduce

use the following test

def test_move_agent_closest_selection_multiple(self):
    random_locations = []
    agent = self.agents[0]
    agent.pos = (5, 5)
    repetititions = 10

    for _ in range(repetititions):
        possible_positions = [(4, 4), (6, 6), (10, 10), (20, 20)]
        self.space.move_agent_to_one_of(
            agent, possible_positions, selection="closest"
        )
        random_locations.append(agent.pos)
        assert agent.pos in possible_positions
        self.space.move_agent_to_one_of(agent, [(5, 5)], selection="closest")
    non_random_locations = [random_locations[0]] * repetititions
    assert random_locations != non_random_locations

Additional context