Я бы хотел, чтобы каждый агент спрашивал своих соседей об их значении переменной, принадлежащей черепахе, и устанавливал их в соответствии с различиями, которые имеют.
Я знаю, как сделать это для расстояний:
if (any? other turtles-here)
[
ask neighbors [ ;; ask 8 neighbors / neighbors4 for 4
;if (max-one-of turtles [distance myself]) <= 3
;[set opinion opinion - .1] ; no change in opinion
;if (distancexy point1-pxcor point1-pycor) > 20 and (distancexy point1-pxcor point1-pycor) <= 50
;[set point1-location "middle"]
;if (distancexy point1-pxcor point1-pycor) > 50
;[set point1-location "far"]
]
однако я борюсь с его реализацией для обмена ценностями.Как мне этого добиться?
Это мой MWE.
Обратите внимание, что рассматриваемая часть кода находится в псевдокоде.
breed [ turtles ]
turtles-own [ variable ]
to setup
clear-all
create-turtles 100
[
set variable random-float 10
]
reset-ticks
end
to communicate
if (any? other turtles-here)
[
ask neighbors [
pseudo-code: if difference of your variable and my variable is bigger then 3, than do nothing
if differences less then 3, calculate the higher variable minus 0.1 and the lower variable plus 0.1
if difference less then 2, calculate the higher variable minus 0.3 and the lower plus 0.3
if difference less then 1, calculate the arithmetical mean
]
]
end
to go
ask turtles [
rt random 360
fd 1
communicate
]
tick
end