如何避免海龟重新访问他们上次的补丁?

时间:2014-06-25 08:12:13

标签: netlogo

海龟在补丁上停留60个蜱虫,然后转移到另一个目标补丁。如何避免海龟重新访问他们上次的补丁?感谢

嗨塞思和弗兰克,

非常感谢您的回复。对不起,我没有详细描述这些问题。

海龟将不会访问他们在最后一个刻度线上的补丁,并将转移到另一个最近的补丁而不是下一个滴答。以下代码表示他们找到最近的补丁,并继续前进。

我想要做的是乌龟会在下一个勾号中再次找到最近的补丁。如果最近的补丁仍然是最后一个补丁上的补丁,他们将转移到距离他们最近的其他替代方案。谢谢

let closest-leaf min-one-of (patches in-radius 1 with [pcolor = lime]) [distance myself]

face closest-leaf

fd distance closest-leaf

2 个答案:

答案 0 :(得分:5)

一个好方法是让一个海龟自己的补丁变量可以维护(记得在创建乌龟时将其初始化为空列表)。

turtles-own [ patches-visited ]

to setup
  ...
  ask turtles [ set patches-visited [] ]
  ...
end

to move
  let potential-targets filter [ not member? ? patches-visited ] target-patches
  let target-patch one-of potential-targets

  if target-patch != NOBODY [
    set patches-visited fput target-patch patches-visited
    ; move to target patch
  ]
end

答案 1 :(得分:3)

添加get-target记者。

to-report get-target  ;;turtle proc
  let %close patches in-radius 1 with [pcolor = lime and self != [patch-here] of myself]
  ifelse (any? %close) [
    report min-one-of %close [distance myself]
  ] [
    report nobody
  ]
end

现在,您可以轻松改变关于如何选择目标的想法。然后,您可以移动到目标(如果存在)。

to move  ;; turtle proc
  let %target get-target
  ifelse (%target = nobody) [
    ;handle this case
  ] [
    face %target move-to %target
  ]
end
相关问题