靠近海龟
Get closer turtles
我使用的是 netlogo 6.0.4,我想从乌龟那里得到更近的乌龟。
我使用此代码:
create-players 1[
set color red
set size 5
set the-player self
set team "red"
]
create-balls 1 [
set color orange
set size 2.5
set the-ball self
]
to-report get-players-close-to-ball
report players with [distance the-ball <= 1]
end
但我得到的输出(agentset,0 只海龟)我无法像这样与自己进行比较:
to-report decision-steal-ball
let decision 0
if (self = get-players-close-to-ball)[
set decision 10
]
report decision
end
。
所以我尝试使用 :
to-report get-players-closer-to-the-ball
report the-player with [distance the-ball <= 1]
end
但是我收到了这个错误:
"WITH expected input to be an agentset but got the turtle (player 10) instead."
所以问题是:如何让球员离球更近?
你的第一个代码在一个过程中有 to-report
,甚至在试图偷球之前就会产生错误。您还有一个概念性问题 - 球附近可能有任意数量的球员。该消息告诉您当时没有球员靠近球。
NetLogo 正在返回一个代理集,其中包含所有靠近球的球员。无法像 'if self = agentset' 那样测试代理集。你需要的是 if member? self get-players-close-to-ball
,它将检查自己是否是代理集的成员。更好的是,即使代理集为空,它也能正常工作,因此您不必先进行测试 if any?
。
我使用的是 netlogo 6.0.4,我想从乌龟那里得到更近的乌龟。
我使用此代码:
create-players 1[
set color red
set size 5
set the-player self
set team "red"
]
create-balls 1 [
set color orange
set size 2.5
set the-ball self
]
to-report get-players-close-to-ball
report players with [distance the-ball <= 1]
end
但我得到的输出(agentset,0 只海龟)我无法像这样与自己进行比较:
to-report decision-steal-ball
let decision 0
if (self = get-players-close-to-ball)[
set decision 10
]
report decision
end
。 所以我尝试使用 :
to-report get-players-closer-to-the-ball
report the-player with [distance the-ball <= 1]
end
但是我收到了这个错误: "WITH expected input to be an agentset but got the turtle (player 10) instead."
所以问题是:如何让球员离球更近?
你的第一个代码在一个过程中有 to-report
,甚至在试图偷球之前就会产生错误。您还有一个概念性问题 - 球附近可能有任意数量的球员。该消息告诉您当时没有球员靠近球。
NetLogo 正在返回一个代理集,其中包含所有靠近球的球员。无法像 'if self = agentset' 那样测试代理集。你需要的是 if member? self get-players-close-to-ball
,它将检查自己是否是代理集的成员。更好的是,即使代理集为空,它也能正常工作,因此您不必先进行测试 if any?
。