NetLogo - 将海龟移动到最近的海龟

问题描述

我遵循模型库的“银行准备金”模型和“走向目标示例”代码示例的混合原则。但不是将一个人(海龟)移动到一个随机的银行(海龟),我需要这个人(海龟)移动到最近的银行(海龟)。按照我的代码尝试:

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)

接下来我可以尝试什么?

解决方法

为了将人(乌龟)移动到最近的银行(乌龟),我使用了以下代码行:

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-ofmyself 是此解决方案的关键字。

,

distance 的 NetLogo 字典条目与您的问题非常相似 - 在这种情况下,找到最远的海龟。你还没有告诉distance去哪里找距离,问乌龟。试试这个:

move-to min-one-of banks [distance myself]

但是,我认为您编码的方式应该会生成错误消息,所以我不确定其他地方是否还有其他问题。