如何在不同颜色的斑块中移动海龟

时间:2014-04-11 15:03:47

标签: netlogo

抱歉,我还不熟悉Netlogo。我的原语" n-of"有问题。我在世界上有100个人。从100个人,我想在道路上移动52个人,在田地里移动48个人。

let turtle-%-in-roads 52
let turtle-%-in-fields 48

create-turtles 100 

ask n-of round ( (100 * turtle-%-in-roads) / 100 ) turtles [  move-to one-of patches with [pcolor = white] ]
print count turtles-on patches with [pcolor = white] ;; give 52 OK

ask n-of round ( (100 * turtle-%-in-fields) / 100 ) turtles [  move-to one-of patches with [pcolor = brown] ]
  print count turtles-on patches with [pcolor = brown] ;; give 73 

 print count turtles-on patches with [pcolor = white] ;; give 27 
 print count turtles-on patches with [pcolor = brown] ;; give 73

我不明白为什么我有27个人而不是道路上的52个人和73个人而不是48个人? 在此先感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

第一个问题是成功地将52只乌龟移到了公路上,但第二个问题就是把这些海龟中的一些带到田里。你想要第二个问题只影响不在道路上的海龟。所以:

ask n-of round ( (100 * turtle-%-in-fields) / 100 ) turtles with [ pcolor != white ] [
  move-to one-of patches with [pcolor = brown]
]