netlogo:如何使海龟停下一定数量的滴答声然后继续 [英] netlogo: how to make turtles stop for a set number of ticks then continue

查看:366
本文介绍了netlogo:如何使海龟停下一定数量的滴答声然后继续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个模型,使海龟随机行走(但有向前运动的趋势),直到它们降落在代表诱饵物体的黄色斑块上.

I'm trying to create a model where turtles walk randomly (but with a tendency for forward movement) until they land on a yellow coloured patch which represents a baited object.

当乌龟降落在其中一个黄色斑块上时,我希望它停在那个斑块上并在那儿呆15刻,同时调查"诱饵.

When a turtle lands on one of the yellow patches, I'd like it to stop on that patch and stay there for 15 ticks whilst it 'investigates' the bait.

经过15个滴答声之后,我希望海龟继续照常移动,直到遇到另一个黄色斑块为止.

After 15 ticks have elapsed I want the turtles to continue moving as usual until they encounter another yellow patch.

我曾尝试在netlogo建模公用程序中修改此停放卡模型的一部分,但无法真正理解它(我是netlogo的新手) http://modelingcommons.org/browse/one_model/3205#model_tabs_browse_procedures

I've attempted to modify parts of this parked card model in the netlogo modelling commons but couldn't really make sense of it (I'm new to netlogo) http://modelingcommons.org/browse/one_model/3205#model_tabs_browse_procedures

我也曾尝试实现此线程中所述的倒数计时器 如何在NetLogo中创建倒数计时器?

I've also tried implementing a count-down timer as described in this thread How can one create a countdown timer in NetLogo?

但是,当我尝试运行模拟时,收到运行时错误只有观察者可以询问所有乌龟的集合".谁能告诉我我要去哪里错了?大概几个地方!谢谢.

However I receive a runtime error 'Only the observer can ASK the set of all turtles' when I try to run the simulation. Can anyone tell me where I'm going wrong? Probably several places! Thanks.

以下是导致运行时错误的代码:

Here's the code that's causing the runtime error:

turtles-own [count-down]

to setup 
clear-all
ask patches with [count neighbors != 8]
[set pcolor blue]                   

create-turtles 20
ask turtles 
 [setxy random-xcor random-ycor 
 pen-down]   

ask n-of 20 patches
[ set pcolor yellow ]                   

reset-ticks
end

to go
 move-turtles
 tick
 if ticks >= 720 [stop]

 end


to move-turtles
ask turtles
  [ ifelse pcolor != yellow
  [continue]
  [stay]
  ]
 end

 to continue
ask turtles   
[rt -90 + random 181]
ask turtles
[ifelse [pcolor] of patch-ahead 1 = blue [ lt random-float 360 ]   
[fd 1]  
]
end

to stay
ask turtles 
[
setup-timer
decrement-timer
if timer-expired? [continue]
]
end

to setup-timer
set count-down 15
end

to decrement-timer
set count-down count-down - 1
end

to-report timer-expired?
report ( count-down <= 0 )
end

推荐答案

这只是一个示例,他们应该在黄色区域留几格?我假设有15个滴答声,我也要求海龟在标签上打印它们的滴答声编号,如果它运行得太快,您可能会错过它们的停留,因此请调整模型的运行速度,以查看它们何时停留以及何时移动.您可以使用不同的方法继续,在此方法中,他们只向前移动了1个补丁.

This is just one example, How many ticks they should stay in the yellow area? i Assumed 15 ticks and I ask turtles to print their tick number on their label too, if it runs too fast you might miss their stay so adjust running speed for your model to see when they stay and when they move. You can have different methods to continue , in this one they just move 1 patch forward.

turtles-own [count-down]

to setup 
  clear-all
  ask patches with [count neighbors != 8]
  [set pcolor blue]                   

  create-turtles 20
  ask turtles 
  [setxy random-xcor random-ycor 
    pen-down
    set count-down 15
  ]   

  ask n-of 20 patches
  [ set pcolor yellow ]                   

  reset-ticks
end

to go
  move-turtles
  tick
  if ticks >= 720 [stop]

end


to move-turtles
  ask turtles
  [ ifelse pcolor != yellow
    [continue]
    [stay]
  ]
end

To continue   
  rt random 10
  fd 1 
end


to stay   
  set count-down count-down - 1   ;decrement-timer
  set label count-down    
  if count-down = 0 
    [
      Continue
      set label ""
      reset-count-down
    ]    

end

to reset-count-down   
  set count-down 15 
end

这篇关于netlogo:如何使海龟停下一定数量的滴答声然后继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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