到目前为止,这是我的代码。我只希望乌龟遵循绿线,但是当我设置模型时,它们只会在面对的随机方向上永远持续下去。
代码:
extensions [gis]
breed [observer]
turtles-own [ vision-distance vision-width steps green-steps gray-steps attr-prob]
patches-own [land nearest-patch]
to setup
clear-all
create-turtles 10
set-default-shape turtles "butterfly"
ask turtles [set size 25
if pxcor = min-pxcor [die]]
reset-ticks
let view gis:load-dataset "City_Plan_Boundary.shp"
gis:set-world-envelope gis:envelope-of view
foreach gis:feature-list-of view
[
gis:set-drawing-color green
gis:draw ? 1.0
]
end
to go
ask turtles [
count-steps
pen-down
let green_target turtles
let perceived_patches patches in-cone vision-distance vision-width
let patch-under-me patch-here set green_target perceived_patches with [ (pcolor = green and self != patch-under-me) or (pcolor = black and self != patch-under-me)]
ifelse count green_target != 0 [
let target min-one-of green_target[ distance myself ]
let target_heading towards target
move-to patch-at-heading-and-distance target_heading 1 ]
[ fd 1]
]
end
to count-steps
set steps steps + 1
ifelse land = green [set green-steps green-steps + 1][set gray-steps gray-steps + 1] ;;Does not currently account for CYAN Park squares
end
答案 0 :(得分:0)
首先,应用GIS层的foreach
循环仅在NetLogo的drawing layer中创建行,而实际上并未更改补丁本身。您必须将shapefile的某些组件分配给补丁本身,以便海龟能够对其进行评估-请查看“模型库”中的“ GIS常规示例”模型。
第二,寻路可以通过多种方式来完成,这实际上取决于您要建模的行为。对于一些示例,请查看模型库中的“向前看”示例,或者查看下面的玩具模型以获取非常简单的方法:
to setup
ca
ask patch min-pxcor 0 [
set pcolor green
sprout 1 [
set color red
pd
]
spread-right
]
reset-ticks
end
to spread-right
if pxcor < max-pxcor [
ask one-of neighbors with [ pxcor = [pxcor] of myself + 1] [
set pcolor green
spread-right
]
]
end
to go
ask turtles [
let target one-of neighbors in-cone 1.5 90 with [ pcolor = green ]
ifelse target != nobody [
face target
move-to target
] [
rt one-of [ 45 -45 ]
]
]
tick
end