NetLogo - 如何获得乌龟面对的所有补丁?
NetLogo - how do I get all patches the turtle facing?
如何获得包含乌龟面对的所有补丁的补丁集?
我知道补丁提前报告具有特定距离的补丁。但是如果我想得到这个方向的所有补丁而不是具有特定距离的单个补丁怎么办?
你可以做的是 hatch
一只乌龟并移动它 forward
直到它到达世界的边缘,添加它穿过的所有补丁。
这里有一个可见的版本来查看方法:
to testme
clear-all
create-turtles 1 [setxy random-xcor random-ycor]
ask one-of turtles
[ set pcolor red
hatch 1
[ while [can-move? 1]
[ forward 1
set pcolor red
]
die
]
]
end
要实际制作补丁集版本,您需要从当前补丁开始,并在孵化的海龟移过它们时添加补丁。试试这个程序版本和如何使用它的演示:
turtles-own [ my-path ]
to testme
clear-all
create-turtles 1 [setxy random-xcor random-ycor]
ask one-of turtles
[ set my-path get-patches-forward self
print my-path
]
end
to-report get-patches-forward [ #me ] ; turtle procedure
let front-patches patch-here
hatch 1
[ while [can-move? 1]
[ forward 1
set front-patches (patch-set front-patches patch-here)
]
die
]
report front-patches
end
如果世界被包裹起来,这将 return 错误的答案,因为孵化的海龟可以无限期地继续下去。相反,您需要检查其坐标而不是依赖 can-move?
原语。
如何获得包含乌龟面对的所有补丁的补丁集?
我知道补丁提前报告具有特定距离的补丁。但是如果我想得到这个方向的所有补丁而不是具有特定距离的单个补丁怎么办?
你可以做的是 hatch
一只乌龟并移动它 forward
直到它到达世界的边缘,添加它穿过的所有补丁。
这里有一个可见的版本来查看方法:
to testme
clear-all
create-turtles 1 [setxy random-xcor random-ycor]
ask one-of turtles
[ set pcolor red
hatch 1
[ while [can-move? 1]
[ forward 1
set pcolor red
]
die
]
]
end
要实际制作补丁集版本,您需要从当前补丁开始,并在孵化的海龟移过它们时添加补丁。试试这个程序版本和如何使用它的演示:
turtles-own [ my-path ]
to testme
clear-all
create-turtles 1 [setxy random-xcor random-ycor]
ask one-of turtles
[ set my-path get-patches-forward self
print my-path
]
end
to-report get-patches-forward [ #me ] ; turtle procedure
let front-patches patch-here
hatch 1
[ while [can-move? 1]
[ forward 1
set front-patches (patch-set front-patches patch-here)
]
die
]
report front-patches
end
如果世界被包裹起来,这将 return 错误的答案,因为孵化的海龟可以无限期地继续下去。相反,您需要检查其坐标而不是依赖 can-move?
原语。