报告给定乌龟周围的特定补丁

时间:2017-02-06 19:30:04

标签: netlogo

如何根据此图像使用邻居函数立即报告位于每只乌龟周围的所有补丁?

enter image description here 请注意,在下面详述的示例中,行和列从世界的左上角开始。因此,(1,1)是左上角的补丁索引。

假设乌龟A(图像中的红叉)位于补丁x0 y0处,此乌龟周围的邻近补丁将是:

%%%方向1:左上角的补丁 show patch (x0 – 2):(x0 – 1) (y0 – 2):(y0 – 1)返回带坐标(1,1),(1,2),(2,1),(2,2)的补丁

%%%方向2:中上角的补丁 show patch (x0 – 2):(x0 – 1) (y0 – 1):(y0 +1)返回带坐标(1,2),(1,3),(1,4),(2,2),(2,3),(2,4)的补丁

%%%方向3:右上角的补丁 show patch (x0 – 2):(x0 – 1) (y0 + 1):(y0 + 2)以坐标(1,4),(1,5),(2,4),(2,5)返回补丁

%%%方向4:左角的补丁 show patch (x0 – 1):(x0 + 1) (y0 – 2):(y0 – 1)返回带坐标(2,1),(2,2),(3,1),(3,2),(4,1),(4,2)的补丁

%%%方向5:右上角的补丁 show patch (x0 – 1):(x0 + 1) (y0 + 1):(y0 + 2)以坐标(2,4),(2,5),(3,4),(3,5),(4,4),(4,5)返回补丁

%%%方向6:左下角的补丁 show patch (x0 + 1):(x0 + 2) (y0 - 2):(y0 - 1)返回带坐标(4,1),(4,2),(5,1),(5,2)的补丁

%%%方向7:底部中间角的补丁 show patch (x0 + 1):(x0 + 2) (y0 - 1):(y0 + 1)返回带坐标(4,2),(4,3),(4,4),(5,2),(5,3),(5,4)的补丁

%%%方向8:右下角的补丁 show patch (x0 + 1):(x0 + 2) (y0 + 1):(y0 + 2)返回带坐标(4,4),(4,5),(5,4),(5,5)的补丁

1 个答案:

答案 0 :(得分:1)

你可以围绕patch-at

的使用进行构建
to setup
  clear-all
  create-turtles 1 [ setxy 3 3 ]
  ask turtles [
    show patches-at [[-2 0] [-1 0] [0 -2] [0 -1]]
  ]
end

to-report patches-at [ list-of-xy-pairs ]
  report patch-set map get-patch-at list-of-xy-pairs
end

to-report get-patch-at [ xy-pair ]
  report patch-at first xy-pair last xy-pair
end
相关问题