还有一些乌龟可以移动到的补丁,但是错误

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

我要求乌龟A移动到与乌龟A具有相同乌龟类型的邻居的补丁。它工作良好,直到出现错误(MOVE-TO预期输入是代理但没有NOBODY)出来。视觉上仍然有一些可用的修补程序。如何编写代码以使所有可用的补丁都被占用,并且在没有更多补丁要占用时报告或停止程序?任何评论将非常有帮助。我做了以下事情:

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]
    ifelse target != 0 and (status != "resident") [move-to min-one-of target [value]
                                              set status "resident"
                                              set color blue]
                                              []   
  ] 

end 

这是完整代码

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]
    ifelse target != 0 and (status != "resident") [move-to min-one-of target [value]
                                              set status "resident"
                                              set color blue]
                                              []   
  ] 

end 

enter image description here

netlogo
1个回答
0
投票

此行:let target pot-target with [count neighbors with [any? turtles-here with [value < 11]] = 1]标识恰好有1个满足这些条件的邻居的补丁。因此,带有2个这样的邻居的补丁将不可用。根据您的描述,我认为您确实想要> =而不是=:

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

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