让特定颜色的乌龟在Netlogo中的特定颜色补丁上做某事

问题描述 投票:0回答:1

对不起,对于新手问题,但是我已经到处寻找该问题的解决方案。我正在建立一个Netlogo模型,学生和犯罪分子在大学校园中进行互动。如果罪犯离学生很近,就会进行追赶,以便当罪犯的距离小于1时,学生会死亡。除了在犯罪分子关闭时死亡之外,我还希望学生(领导者)在追赶时在绿地上死亡。从这个意义上讲,绿色补丁等同于“安全”区域。我已经为追捕罪犯(追随者)和让学生逃跑(领导)设置了程序,但是我遇到了一个完全障碍,就是让学生在遇到绿色补丁时被追杀而丧生。我曾经想过要按照追随者程序让学生陷入困境:

ask students[
      set no-threat criminals in-radius 25
      ifelse any? no-threat[set color blue][set color black]

      ]

然后让蓝色学生在遇到绿色补丁时死亡。我想我缺少明显的东西来使它工作。任何朝着正确方向的微动将不胜感激!

仅供参考,我在这里问问题还比较陌生,因此所有人为任何论坛的歉意道歉

这是我一直在努力参考的程序的内容'''

to move-to-student
  ask criminals[
    set candidate students in-radius 25

    if any? candidate[
      set leader min-one-of candidate [distance myself]
      if leader != nobody [ set color red]

      ;set follower myself
      face leader
      fd .3
      if [pcolor] of patch-ahead 5 = 2.2 [
    set heading heading - 100]
      ]
      ]
end
to run-from-criminal
  ask students[
  ;while[distance follower > 1][
    set threat criminals in-radius 25
    if any? threat[
      set follower min-one-of threat [distance myself]
       if distance follower < 1 [ set number-dead number-dead + 1 die]; set candidate leader set threat follower ] ;students 'die' if criminal gets to close


       if threat != nobody [set color blue] 
       face follower
       rt 180 lt random 20 rt random 20 fd .2
       if [pcolor] of patch-ahead 5 = 2.2 [
        set heading heading - 100]

    ]]



end

to safe-die
  ask students[
      if follower = blue and if [pcolor] of patch-here = green [die]
  ]

end
to revert-leader

ask students[
  set no-threat criminals in-radius 25
  ifelse any? no-threat[set color blue][set color black]

  ]

end

to create-new-students
  ask students[
     if count students < student-count [hatch 1 setxy random-xcor random-ycor]
    ]
end

谢谢!

netlogo agent-based-modeling
1个回答
0
投票

好吧,我知道了。也许写下来有帮助。看来我的解决方案是一个嵌套的if语句(之前我曾尝试过并失败的事情)和将要死亡的代理分配给一个代理集的组合。可能会有更好的方法来完成此操作,但是我想分享我得到的解决方案...

ask students[
    if any? no-threat[if [pcolor] of patch-here = green [die]
    ]

谢谢

© www.soinside.com 2019 - 2024. All rights reserved.