我目前正在做关于路径规划的项目。
所以我计划的步骤是这样的:
这里我附上了界面和编码
to setup
clear-all
set-default-shape turtles "x"
create-turtles 9
ask turtles[set color red]
ask turtle 0[setxy 0 15]
ask turtle 1[setxy 4 15]
ask turtle 2[setxy -4 15]
ask turtle 3[setxy 0 12]
ask turtle 4[setxy 4 12]
ask turtle 5[setxy -4 12]
ask turtle 6[setxy 0 9]
ask turtle 7[setxy 4 9]
ask turtle 8[setxy -4 9]
end
to start
set-default-shape turtles "airplane"
create-turtles 1
ask turtle 9[setxy 0 -15]
end
答案 0 :(得分:1)
请勿忘记距离取决于您的拓扑结构。
to setup
clear-all
let targets [
[0 15] [4 15] [-4 15]
[0 12] [4 12] [-4 12]
[0 9] [4 9] [-4 9]
]
foreach targets [xy -> ask patch item 0 xy item 1 xy [
sprout 1 [set shape "x" set color red]
]
]
create-turtles 1 [ set shape "airplane" setxy 0 -15]
end
编辑:如果您将所有其他海龟视为符合条件的目标,那么一旦您将turtle 9
移至目标,它就会留在那里。如果你不想这样,你说同一地点的乌龟不符合条件:
to move
ask turtle 9 [move-to min-one-of eligibles [distance myself]]
end
to-report eligibles
report turtles with [0 < distance myself]
end