NetLogo - 当代理位于顶部时更改补丁的颜色

标签 netlogo

我试图让我的乌龟在接触到补丁时改变它的颜色,并尝试了以下代码:

to deesculateviolence
  ask turtles [
    if pcolor = red [set pcolor blue]
  ]
end

代码没有出现任何错误,但是当我播放模型时,补丁的颜色没有改变。我已经尝试过不同型号的类似代码,但仍然无法让补丁改变颜色。如果有人知道我哪里出了问题,我将非常感谢您的帮助。

最佳答案

我认为你的代码做了正确的事情:

to setup

  clear-all

  create-turtles 5 [
    move-to patch random 20 random 20

  ]
  ask n-of 25 patches [set pcolor red]
  reset-ticks
end

to go

  ask turtles [
  rt random 10
  fd 1

    if pcolor = red [set pcolor blue]
  ]
  tick
end

enter image description here

enter image description here

下面的例子可以更好的看到效果 enter image description here

enter image description here

关于NetLogo - 当代理位于顶部时更改补丁的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20459924/

相关文章:

Netlogo 鼠标悬停/鼠标悬停

netlogo - 对 NetLogo 语法 (`word` 和 `runresult` 感到困惑)

gis - 让海龟移动到 gis 点

social-networking - NetLogo 创建固定数量链接的有效方法

nested-lists - 更改嵌套列表中的过滤值

netlogo - 要求红海龟避开其他海龟并移动到其空的且浓度最高的邻居之一

netlogo - 在 NetLogo 中使用向量

NetLogo 定制贴片网格

random - 网络标志 : How to make sure a variable stays in a defined range?

java - 是否可以用 Java 编写 NetLogo 仿真程序?