当没有更多可用色块时打印“不显示色块”

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

我想在没有更多可用补丁时打印“无路径”,而不是收到错误消息“ 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 

netlogo
1个回答
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")]

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