计算特定补丁的邻居乌龟并报告是非 [英] Count neighbors turtles of a specific patch and report true or false

查看:88
本文介绍了计算特定补丁的邻居乌龟并报告是非的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我会尽快 我有一间火在蔓延的房间,我有两个出口,我只想对特工说,如果一扇门被火堵住了,就去另一扇.我想出了类似的方法,但没有结果.

Hello i will try to be quick I have a room with a fire that expands , and i have two exits , all i want to do is say to agents that if a door is blocked by fire then to go to the other one. i came up with something like this but not result.

to doorblock
show count neighbors with [pcolor = 77] ;; the patch color of the two doors
end

;;to go 

  ask smarts [    ;;smarts are the agents inside the room that need to get oout
    if [ doorblock > 5 ]    
   [ set target one-of sexits]]  ;;sexits is the other door

有人有更好的主意吗?谢谢

Anyone got a better idea? Thanks

推荐答案

好的,因此,如果我正确理解,您希望您的特工查看作为其当前目标的门,请检查该门是否超过5个射击周围的灭火剂,如果是这种情况,请选择另一个目标门.

OK, so if I understood correctly, you want your agents to take a look at the door that is their current target, check if that door has more than 5 fire agents around it, and choose another target door if that is the case.

如果您的灭火剂只是红海龟(没有特定的品种),您可能想要这样的东西:

If your fire agents are just red turtles (with no specific breed), you probably want something like this:

ask smarts [
  if count ([ turtles-on neighbors ] of target) with [ color = red ] > 5 [
    if-else ([ breed ] of target = sexits )
      [ set target one-of nexits ]
      [ set target one-of sexits ]
  ]
]

这里的关键原语是:

  • neighbors ,这将为您提供乌龟周围的补丁(在这种情况下,target周围的补丁)
  • turtles-on ,这将为您提供<修补程序集成员中的em> turtles (这里是targetneighbors的修补程序中的turtles)
  • 最后, with 仅允许您获取满足某些条件的agentset中的海龟(在这里,我们用它来获取代表火的红色海龟).
  • neighbors, that will give you the patches around a turtle (the patches around target, in this case)
  • turtles-on, that will give you the turtles that are on members of a patch set (here, that will be the turtles that are on the patches that are the neighbors of target)
  • and finally, with allows you to get only the turtles from an agentset that satisfy some condition (here, we use it to get only the red turtles that represent the fires).

您还应该尝试理解 of 原语.

You should also try to understand the of primitive.

我猜您想分配一个新的目标,该目标的品种与先前的目标不同(南为北,南为北),但这取决于您.

And I guessed you wanted to assign a new target that was of a different breed than the previous one (south if north, north if south) but that's up to you.

这篇关于计算特定补丁的邻居乌龟并报告是非的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆