【问题标题】:Netlogo: Can a turtle include another turtle?Netlogo:一只乌龟可以包括另一只乌龟吗?
【发布时间】:2015-02-23 22:28:03
【问题描述】:

Netlogo:一只乌龟可以包括另一只乌龟吗? 伪代码: 如果 turtle1

【问题讨论】:

  • 你能澄清一下包含在另一只海龟中的意思吗?
  • 感谢您的快速回复。乌龟2吞没乌龟1
  • "engulf" 并没有比 "include" 更好地解释它

标签: windows netlogo


【解决方案1】:

也许不完全包括,但海龟可能会在自己的变量中收集其他不幸代理的列表。查看手册中的agentsets

示例:

声明海龟变量

turtles-own [
  swallowed; agentset of the turtles I've eaten
]

创建代理时将此代理集设置为空

to setup
  create-turtles 1 [ 
    set swallowed no-turtles
  ]
end

让乌龟互相吃掉

to swallow
  if any? other turtles-here [
    set swallowed (turtle-set swallowed other turtles-here) 
  ]
end

让海龟这样做:

to go
  ; ...

  ask turtles[ swallow ]

  ; ...
end

但是 - 不要让被吞下的海龟死去(如您的伪代码中所建议的那样),因为它们也会从代理集中消失。定义另一个代理变量(例如is-alive?)并在吞咽过程中将其设置为false。然后你可以隐藏所有吃掉的特工。

【讨论】:

    【解决方案2】:

    再次感谢您的回答。 伪代码: Ifelse Turtle1 死了 ;; Turtle1 和 Turtle2 来自不同的品种 ;;这不是同类相食的情况

    【讨论】:

    • 欢迎来到 StackOverflow!请不要将 cmets 作为答案发布 - 这应该被删除并作为对现有答案的评论提交。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-09
    • 2022-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多