【问题标题】:Netlogo hide-turtleNetlogo 隐藏龟
【发布时间】:2015-04-15 13:48:43
【问题描述】:

这是一个 Netlogo 初学者问题。我创建了一个模型,鸟类将在特定路线上飞行。我通过在补丁上放置 10 只我称为“rasts”(休息处)的海龟并将它们相互连接来创建这条路线。现在,我想让鸟儿在这些路线上飞行,当休息的地方消失时(通过使用“开/关”开关),它们将采取另一条路线。 我的问题:目前我有 5 个 rasts,但只有第一个可以使用开关关闭。有没有人有想法,如何解决这个问题?

这是我的代码:

breed [rasts rast]
breed [birds bird]

to setup
 setup-rasts
 hide-rasts1 
 hide-rasts2 
 hide-rasts3 
 hide-rasts4
 hide-rasts5
end 

to setup-rasts
 set-default-shape rasts "circle"                  
 create-rasts 1 [setxy -12 36 ]
end

to hide-rasts1                                        
 ifelse rast-1? [ ask rast (number-of-birds + 0) [ set hidden? true] ]
               [ ask rast (number-of-birds + 0) [ set hidden? false] ]
end

【问题讨论】:

  • Bergant 对 hide-turtle 部分给出了很好的答案。你能问一个单独的具体问题吗?
  • 我有 3 条由链接构建的路线。每条路线包含 4 个“rasts”。现在,鸟儿将沿着一条路线(从 rast1 移动到 rast2)直到“rast”消失。当一只鸟消失后,鸟儿不得不寻找附近的另一个“鸟”,但它们不应该回到第一个休息的地方。
  • 我现在把海龟运动的代码放在我的问题中。 ;-)
  • 请开始一个新问题,不要在 cmets 中提出新问题。 StackOverflow 的重点是创建资源。因此,标题、问题和答案应相互匹配且具体,以便其他人也能从您的问题中受益。

标签: hide netlogo turtle-graphics


【解决方案1】:

第一个问题:

  1. 难道不能通过使用 下面的代码?

您可以要求隐藏的海龟列表:

; hide all turtles
ask turtles [ hide-turtle ]
; hide all your "rasts"
ask rasts[ hide-turtle ]
; hide random 4 of your turtles
ask n-of 4 turtles [ hide-turtle ]

至于2.问题

  1. 是否可以让乌龟(鸟)跟随路线改变它, 当那里有另一只乌龟(rast)时?

答案是当然有可能,但这个问题以某种方式笼统地提出了一个精确的解决方案。您可以使用face 命令将海龟指向正确的方向。为了感应最近的海龟,检查距离最小的海龟。例如(在海龟的上下文中):

set nearest-rast min-one-of (other rasts) [ distance myself ] 

【讨论】:

    猜你喜欢
    • 2011-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 2020-08-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多