没有更多补丁可使用时,打印“无补丁”

时间:2020-03-09 07:14:40

标签: netlogo

我想在没有更多色块要占用时打印“无路径”,而不是收到错误消息“ MOVE-TO预期输入是代理,但没有提示”。我做了几件事,但是没用。最后,我执行了以下操作;

 ask migrants
  [let pot-target patches with [value < 11 and not any? turtles-here]
   let target pot-target with [count neighbors with [any? turtles-here with [value < 11]] >= 1]
    if target = 0 [print (word "no patch")]
    if (target != 0 and (status != "resident")) [move-to min-one-of target [value]
                                              set status "resident"
                                              set color blue]


  ] 

这是完整的代码

breed [migrants migrant]
breed [residents resident]

patches-own [value]
turtles-own [income
status]

to setup
  ca
  let total problo + probmid + probhi
  if (total != 100) 
     [print (word "prob is more than 100")]
  ask patches [set value random-normal 10 3
  let patch-value value
    set pcolor scale-color (gray - 5) patch-value 10 3]
  ask patches
  [if random 100 < 3
    [sprout-residents 1
      [set color red
       set shape "default"
       set size 1
       set status "resident"   
      ]
    ]
  ]
end

to go

  ask patches 
  [if random 100 < 1 
    [sprout-migrants 1
      [set color green
       set shape "default"
       set size 1 
        set status "migrant"
       set-move 
  ]]]

end

to set-move
 ask migrants
  [let pot-target patches with [value < 11 and not any? turtles-here]
   let target pot-target with [count neighbors with [any? turtles-here with [value < 11]] >= 1]
    if target = 0 [print (word "no patch")]
    if (target != 0 and (status != "resident")) [move-to min-one-of target [value]
                                              set status "resident"
                                              set color blue]


  ] 

end 

1 个答案:

答案 0 :(得分:2)

您正在混合一个代理集和该代理集中的count个代理。这行:

let target pot-target with [count neighbors with [any? turtles-here with [value < 11]] >= 1]

返回一个座席集。因此,变量“目标”是满足您条件的所有补丁。如果没有满足您条件的补丁程序,则代理集不为0,但代理集的count为。

因此,您需要将if target = 0 [print (word "no patch")]替换为if count target = 0 [print (word "no patch")]if not any? [print (word "no patch")]