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

Report specific patches around a given turtle

我怎样才能根据这个图像使用函数 neighbors 立即报告位于每只海龟周围的所有斑块?

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

假设一只海龟 A(图中的红叉)位于块 x0 y0 处,则该海龟周围的相邻块为:

%%%方向一:左上角补丁 show patch (x0 – 2):(x0 – 1) (y0 – 2):(y0 – 1) returns 坐标为 (1,1), (1,2), (2,1), (2,2) 的补丁

%%%方向二:中上角的补丁 show patch (x0 – 2):(x0 – 1) (y0 – 1):(y0 +1) 其中 returns 坐标为 (1,2), (1,3), (1,4), (2,2), (2,3), (2,4)

%%%方向三:右上角补丁 show patch (x0 – 2):(x0 – 1) (y0 + 1):(y0 + 2) 其中 returns 坐标为 (1,4), (1,5), (2,4), (2,5) 的补丁

%%%方向4:左下角的补丁 show patch (x0 – 1):(x0 + 1) (y0 – 2):(y0 – 1) 其中 returns 坐标为 (2,1), (2,2), (3,1), (3,2), (4,1), (4,2)

%%%方向5:右上角的补丁 show patch (x0 – 1):(x0 + 1) (y0 + 1):(y0 + 2) 其中 returns 坐标为 (2,4), (2,5), (3,4), (3,5), (4,4), (4,5)

%%% 方向六:左下角补丁 show patch (x0 + 1):(x0 + 2) (y0 - 2):(y0 - 1) 其中 returns 坐标为 (4,1), (4,2), (5,1), (5,2) 的补丁

%%%方向7:中下角的补丁 show patch (x0 + 1):(x0 + 2) (y0 - 1):(y0 + 1) 其中 returns 坐标为 (4,2), (4,3), (4,4), (5,2), (5,3), (5,4)

%%% 方向八:右下角补丁 show patch (x0 + 1):(x0 + 2) (y0 + 1):(y0 + 2) 其中 returns 坐标为 (4,4), (4,5), (5,4), (5,5) 的补丁

您可以围绕 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