Check if turtles have same x-coordinate and y-coordinate as patches

邮差的信 提交于 2020-01-06 13:54:08

问题


I have a patchset subtractset and some of patches have turtles on it.

Now, I wish to create turtles on only those patches which have different x-cor and y-cor as the patches.

Note: This is different from below code:

  distribute-turtles (population * percent) subtractset with[count turtles-here = 0]

as here a turtle maybe on patch and still have different x-cor and y-cor as the patch.

Thanks. Please let me if there is some ambiguity in my question.


回答1:


Patches have integer coordinates so one way would be to check if the turtles coordinates are integers. round xcor = xcor and round ycor = ycor

Is true iff the turtle is centered on a patch

Or because turtles have access to patch variables

 xcor = pxcor and ycor = pycor

Which is more pleasing to my eye and probably faster.

You could put it in a procedure.

To-report centered 
    Report xcor = pxcor and ycor = pycor
End


来源:https://stackoverflow.com/questions/26690556/check-if-turtles-have-same-x-coordinate-and-y-coordinate-as-patches

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