我试图让汽车以最短的路线访问 50 个不同的城市,每次他访问一个地方时,他都会将城市的颜色从蓝色变为黄色并继续前进,麻烦的是我发现了错误试图找到一种方法来实现这一点。我在最后一行代码中遇到很多错误,它说 CAR 需要 1 个输入,一个数字。任何帮助将不胜感激。
breed [cities city]
breed [cars car]
cars-own [history travelled-distance]
to setup
clear-all
reset-ticks
setup-patches
setup-turtles
end
to setup-turtles
ask n-of 50 patches with [pcolor = 55 and not any? other turtles-here][sprout-cities 1 [set color blue set size 2 set shape "square"]]
create-cars 1[
setxy -90 -90
set color red
set size 5
]
end
to setup-patches
ask patches [set pcolor green]
ask n-of 100 patches [set pcolor brown ask neighbors [set pcolor brown]]
end
to go
ask cars [
pendown
if history <= 50
[ ;set heading towards city in-radius 10]]
move-to min-one-of cities in-radius 360 [distance myself]
]
if car in-radius 5 = true [set color = yellow]]
end
答案 0 :(得分:0)
将航向设置为半径 10 内的一个城市