作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图指示海龟访问所有绿色斑块。
有一种我无法理解的行为:如果原点位置 = 中心,则始终避免补丁 0,0(请参见带有 0,0 蓝色的屏幕截图),如果原点位置 = 角,则始终避免使用左下角.
为什么是这样?我在这里犯了什么错误?
;;==========================================================
globals [
memory
target
]
patches-own [visit-counter]
;;==========================================================
to setup
ca
resize-world -6 6 -6 6
set-patch-size 40
create-turtles 1 [
set memory (list patch-here)
setxy random-pxcor random-pycor
set size 1
set color blue
]
ask patches [if random 100 < 40 [set pcolor green]]
ask patch 0 0 [set pcolor green]
ask patches [set visit-counter 0]
reset-ticks
end
;;==============================================
to go
ask turtles [choose-target]
tick
if ticks > 500 [stop]
end
;;==============================================
to choose-target
pd
;; set of unvisited patches
let unvisited patches with [not member? self [memory] of myself]
;; set of green patches that are not visited
let targets patches with [(member? self unvisited) and (pcolor = green)]
;; select target and move there
set target one-of targets with-min [distance myself]
ifelse target != nobody [
face target
fd 1
set visit-counter (visit-counter + 1)
set memory lput patch-here memory
]
[die
]
end
最佳答案
当您初始化变量 'memory' 时,您有 set memory (list patch-here)
.此时,乌龟正坐在patch 0 0
上,所以原始补丁在内存中。您用于查找目标的代码排除了内存中已有的目标 let unvisited patches with [not member? self [memory] of myself]
.因此,它没有资格被选为目标。
关于Netlogo 龟跳过特定补丁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59353305/
我是一名优秀的程序员,十分优秀!