2015-07-13 103 views
2

我需要检查所有相邻的补丁上是否有龟。我尝试的代码给出了设置原语的“期望记者”的错误。检查所有与海龟有关的8个相邻的补丁? NetLogo

我的代码是

if all? other (people-on neighbors) with [fear?]  [set unable-move? true ] 

人是这一品种,怕是一个属性变量(人自己的变量),无法-的举动?是一个全局变量。

在某些时候,如果包括中央补丁在内的所有8个补丁都有一个人(海龟)并且处于恐惧状态,那么我想停止该人(海龟)。

+0

如果您给出一个可以测试的短代码,这会更容易! – delaye

回答

0

类似:

if sum [count people-here with [fear?]] of neighbors >= 8 [ 
             set unable-move? true 
             ] 

我希望它的作品!

+0

谢谢,但实际上我的意思是尼古拉斯先生回答了什么。 –

1

这应该工作以及:

if (not any? neighbors with [count people-here with [fear?] = 0]) 
[ set unable-move? true ] 
+0

谢谢,但我想检查所有的邻居。 –

3

all?基本要求你给:

  • 您要测试的条件(在你的情况,neighbors)的agentset。
  • 记者在每个代理上测试这个条件(在你的情况中,相邻的补丁):any? people-here with [ fear? ]

一起:

if all? neighbors [ any? people-here with [ fear? ] ] [ 
    set unable-move? true 
] 

这一切就是这么简单!

+0

谢谢先生...... –

相关问题