首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在海龟在Netlogo中做了每一个动作后,我该如何改变它们的航向?

在海龟在Netlogo中做了每一个动作后,我该如何改变它们的航向?
EN

Stack Overflow用户
提问于 2017-02-16 06:44:00
回答 1查看 113关注 0票数 0

在我的模型中,海龟从地图的右侧移动到左侧。在它们穿行的过程中,它们正在寻找绿色的斑块。当他们找到一个,并且它在他们的视锥中时,他们会转身朝它走去。如果有多个等距的补丁,他们会随机选择去哪个补丁。然而,当它们移动时,它们的运动中似乎有很多不必要的抖动。有人能说出原因吗?看看这张照片,http://imgur.com/qOftVPJ。他们应该一直往前走直到他们看到绿色。

代码语言:javascript
复制
to move-bug

    ask bugs [
    count-steps
    if pxcor = min-pxcor [
    file-open data-filename
    file-type data-filename
    file-type " "
    file-type  data-header
    file-write vision-width
    file-write vision-distance
    file-write greenroof-percent
    file-write gray-steps
    file-write green-steps
    file-write steps
    file-type "\n"
    file-close
      ]

     if pxcor = min-pxcor [die]

     set heading 270
     pen-down
     let green_target nobody
     let perceived_patches patches in-cone vision-distance vision-width
     set green_target perceived_patches with [ pcolor = green ]
    ifelse count green_target > 0 [face min-one-of green_target [vision-                 distance]][face min-one-of perceived_patches [vision-distance]] ;; added equivalent jitter to non-green squares

前进1]

代码语言:javascript
复制
   end
EN

回答 1

Stack Overflow用户

发布于 2017-02-16 08:28:39

Ifelse将运行您为其提供的两个命令块中的一个,因此每次运行此过程时,bug都会面对绿色目标补丁(如果绿色补丁在其视线范围内)或感知到的补丁(如果bug看不到任何绿色补丁)。因此,如果移动错误的过程是在move-bug之后调用的,错误将会抖动,因为在实际移动之前,无论运行哪个face行,错误的标题都会发生变化。你真正想要的是让bug只在看到绿色补丁时才面对补丁,所以试着只使用if语句而不是ifelse。此外,您正在使用

min-one-of green_target [vision-distance]

但是你可能想要

min-one-of green_target [distance myself]

选择最近的绿色补丁。我得到了下面的代码来为我工作,但需要注意的是,我只是在我的字段(see image- bugs here move right to left)上随机放置了绿色圆圈。

代码语言:javascript
复制
  set heading 270
  pd       ;; shorthand for pen-down
  let green_target nobody
  let perceived_patches patches in-cone vision-distance vision-width 
  set green_target perceived_patches with [ pcolor = green ]
  print green_target
  if count green_target > 0 [
    face min-one-of green_target [ distance myself ]
  ]

  fd 1
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42261513

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档