我需要检查是否所有邻近的补丁上都有海龟。我尝试的代码使用set primitive给出了"expected“的错误。
我的代码是
if all? other (people-on neighbors) with [fear?] [set unable-move? true ] 人是品种,恐惧是一个属性变量(人自己的变量),不能移动?是一个全局变量。
在某个时候,如果所有的8补丁(包括中心补丁)上都有一个人(乌龟),并且处于恐惧中,我想要阻止这个人(乌龟)。
发布于 2015-07-13 20:33:51
all?原语要求您提供:
用于测试条件的代理集(在您的示例中,是用于在每个代理(在您的示例中是相邻的补丁程序)上测试该条件的neighbors).
any? people-here with [ fear? ].总而言之:
if all? neighbors [ any? people-here with [ fear? ] ] [
set unable-move? true
]非那样做不行!
发布于 2015-07-13 17:08:22
这也应该是可行的:
if (not any? neighbors with [count people-here with [fear?] = 0])
[ set unable-move? true ]发布于 2015-07-13 16:28:32
类似于:
if sum [count people-here with [fear?]] of neighbors >= 8 [
set unable-move? true
]我希望它能起作用!
https://stackoverflow.com/questions/31377080
复制相似问题