【问题标题】:How to stop a turtle netlogo如何阻止乌龟 netlogo
【发布时间】:2015-01-18 08:31:11
【问题描述】:

如果前面有黑斑,我想知道如何阻止我的乌龟(顾客)前进。问题在于 go 按钮是一个永久按钮。我试图让海龟使用坐标转动,但当然这不会阻止海龟向前移动,因为它是一个永远的按钮。这是NetLogo,只是为了澄清。

to go  ;; customer procedure
  ask patrons [
    fd 1
    while [any? other patrons-here]
      [ fd 1 ]
    if pxcor = -15 and pycor = 14
      [rt 90]
      if pxcor = -14 and pycor = 14

  ]

  tick   
end

【问题讨论】:

    标签: button netlogo forever


    【解决方案1】:

    我不完全清楚您是否有多个顾客。如果问题是您想停止模型运行,那么您可以使用stop 原语。如果问题是您想阻止特定的顾客以便它可以做其他事情,那么您可以使用ifelse 原语来检查它是否在每次滴答声中移动或做其他事情

    globals [numwant]
    turtles-own [new?]
    
    to setup
      clear-all
      set numwant 5
      create-turtles 1 [set color green
                        set new? TRUE]
      ask n-of 30 patches [set pcolor red]
      reset-ticks
    end
    
    to go
       ask turtles with [new?]
       [ ifelse [pcolor] of patch-ahead 1 != red
         [ fd 1]
         [ set color yellow
           set new? FALSE
           ifelse count turtles < numwant
           [spawn]
           [stop]
         ]
       ]
      tick
    end
    
    to spawn
      hatch 1 [set color green
               setxy random-xcor random-ycor
               set heading random-float 360
               set new? TRUE]
    end
    

    编辑添加多个海龟和顺序生成以响应评论。但是,您可能需要稍微考虑一下您的逻辑,一次只希望一只乌龟移动是不寻常的。

    【讨论】:

    • 非常感谢,我一直在尝试弄清楚如何使用 stop,这很完美。但是我忽略了问我是否要创建多个赞助人,并且在我的设置中,我在滑块中创建了 15 个赞助人的数量,我如何首先生成一只海龟,到达某个补丁可以说是绿色,然后要求第二个赞助人产卵等等? @JenB
    • @Ivan 我认为 JenB 已经回答了您最初的问题。你应该接受她的回答(旁边有一个大的复选标记)并打开一个新问题,问一些新的东西。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多