gpt4 book ai didi

Netlogo 龟跳过特定补丁

转载 作者:行者123 更新时间:2023-12-04 10:53:27 28 4
gpt4 key购买 nike

我试图指示海龟访问所有绿色斑块。

有一种我无法理解的行为:如果原点位置 = 中心,则始终避免补丁 0,0(请参见带有 0,0 蓝色的屏幕截图),如果原点位置 = 角,则始终避免使用左下角.

enter image description here

为什么是这样?我在这里犯了什么错误?

;;==========================================================
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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com