我正试图指示海龟参观所有绿色补丁。
有一种我无法理解的行为:如果原点位置=中心(请参见屏幕截图,以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
答案 0 :(得分:1)
初始化变量“ memory”时,您有set memory (list patch-here)
。那时,乌龟坐在patch 0 0
上,因此原始补丁位于内存中。您用于查找目标的代码不包括内存let unvisited patches with [not member? self [memory] of myself]
中已经存在的代码。因此,没有资格被选为目标。