function init() { if(id == 0) { # Source robot mydist = 0. } else { # Other robots mydist = 1000. # Listen to other robots' distances neighbors.listen("dist_to_source", function(value_id, value, robot_id) { mydist = math.min( mydist, neighbors.get(robot_id).distance + value) }) } } function step() { neighbors.broadcast("dist_to_source", mydist) } function destroy() { }