There are still some patches that turtle can move on to but ERROR

久未见 提交于 2020-03-23 12:02:35

问题


I ask a turtle A to move to patch that has a neighbor that has the same type of turtle with the turtle A. It is working well until the ERROR (MOVE-TO expected input to be an agent but got NOBODY instead) comes out. Visually there are still some available patches. How to code so that all available patches are occupied and report or stop the program when there is no more patch to occupy? Any comments will be really helpful. I did the following:

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 

This is the full code

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 


回答1:


This line: let target pot-target with [count neighbors with [any? turtles-here with [value < 11]] = 1] identifies the patches where there is exactly 1 neighbour meeting those conditions. So a patch with 2 such neighbours is would not be available. From your description I think you really want >= instead of =:

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



来源:https://stackoverflow.com/questions/60540292/there-are-still-some-patches-that-turtle-can-move-on-to-but-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!