NetLogo - 将海龟移动到最近的海龟
NetLogo - move turtle to closest turtle
我遵循“银行储备”模型和模型库的“迈向目标示例”代码示例的混合原则。但不是将一个人(乌龟)移动到随机银行(乌龟),我需要这个人(乌龟)移动到最近的银行(乌龟)。按照我的代码尝试:
if cash >= 100[ ;; go to the nearest bank for and depose the money for saving
move-to bank with-min [distance]]] ;; move turtle to closest bank (turtle)
接下来我可以尝试什么?
distance
的 NetLogo 字典条目与您的问题非常相似 - 在那种情况下找到最远的海龟。你还没有告诉 distance
求什么距离,会问的乌龟。试试这个:
move-to min-one-of banks [distance myself]
不过,我原以为你的编码方式应该会生成错误消息,所以我不确定其他地方是否还有其他问题。
为了将人(乌龟)移动到最近的银行(乌龟),我使用了以下代码行:
to go
ask persons [
set cash cash - 3 ;; removes 3$ within each tick
set label cash ;; renews the label
if cash <= 0[
move-to min-one-of other banks [distance myself] ;; moves to the closest bank
]
]
min-one-of
和 myself
是此解决方案的关键字。
我遵循“银行储备”模型和模型库的“迈向目标示例”代码示例的混合原则。但不是将一个人(乌龟)移动到随机银行(乌龟),我需要这个人(乌龟)移动到最近的银行(乌龟)。按照我的代码尝试:
if cash >= 100[ ;; go to the nearest bank for and depose the money for saving
move-to bank with-min [distance]]] ;; move turtle to closest bank (turtle)
接下来我可以尝试什么?
distance
的 NetLogo 字典条目与您的问题非常相似 - 在那种情况下找到最远的海龟。你还没有告诉 distance
求什么距离,会问的乌龟。试试这个:
move-to min-one-of banks [distance myself]
不过,我原以为你的编码方式应该会生成错误消息,所以我不确定其他地方是否还有其他问题。
为了将人(乌龟)移动到最近的银行(乌龟),我使用了以下代码行:
to go
ask persons [
set cash cash - 3 ;; removes 3$ within each tick
set label cash ;; renews the label
if cash <= 0[
move-to min-one-of other banks [distance myself] ;; moves to the closest bank
]
]
min-one-of
和 myself
是此解决方案的关键字。